I have array of objects with about 500 records. I would like to loop trough the array of objects and check if object name is equal to one of the elements. Here is example of my array of objects:
data = [
{
"row": 23,
"code": "ERT"
},
{
"row": 45,
"code": "TTR"
},
{
"row": 90,
"code": "CXZ"
}
];
Here is what I tried so far:
data.some(function (obj) {
if(obj.name === "code"){
return obj[name]; // Return value if name exists
}
});
I would like to check if name
exists in the object. If does, pull the value for that name. My code will produce undefined
in the console. Can someone help with this? Is there a way to achieve this?