How to find a value in an array of objects in Javascript?

Rashmi
Rashmi
Member
170 Points
35 Posts

I have following json array object and need to get one item on the basis of some filter:

var array = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

How to find an object value in an array of objects?

Views: 94
Total Answered: 1
Total Marked As Answer: 1
Posted On: 15-Nov-2021 06:30

Share:   fb twitter linkedin
Answers
edx
edx
134 Points
37 Posts
         

try something:

var sigleObject = array.find(x => x.name === 'string 1')

print(sigleObject.value);
Posted On: 16-Nov-2021 04:10
 Log In to Chat