Issue
I want to check if a value exist in an array object. Example:
I have this array:
[
{id: 1, name: 'foo'},
{id: 2, name: 'bar'},
{id: 3, name: 'test'}
]
And I want check if id = 2
exists here.
Solution
You can use Array.prototype.some
var a = [
{id: 1, name: 'foo'},
{id: 2, name: 'bar'},
{id: 3, name: 'test'}
];
var isPresent = a.some(function(el){ return el.id === 2});
console.log(isPresent);
Answered By - Karim
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.