I have a array like this
[{"name":"Typical value Sydney (SUA) Houses", "value":"Bar" },
{"name":"Days on market Sydney (SUA) Houses", "value":"Bar" },
{"name":"Typical value Melbourne (SUA) Houses", "value":"Line" },
{"name":"Days on market Brisbane (SUA) Houses", "value":"Bar" }]
I have another variable that I receive the name "Days on market Sydney (SUA) Houses"
I want to find the the name in the array and get the corresponded value like "Bar"
how do I achieve this in javascript
for (var j = 0; j < arr.length; j++){
if (arr[j].name == seri){
value= arr[j].value;
return true;
}}
it is not going into the if condition .
2
Answers
You can simple use the
Array.find
method in JavaScript.via
Array.prototype.find()
, then can search for a specific object in the array