javascript - how check if element exists in array? -
is there way check if track_id
exists on array?
here array structure, tried use indexof
.
{"playlist":[{track_id : 1}, {track_id : 2}, {track_id : 3}]}
use array#some
method
var obj = { "playlist": [{ track_id: 1 }, { track_id: 2 }, { track_id: 3 }] }; var search_id = 2; var found = obj.playlist.some(function(v) { return v.track_id == search_id; }); console.log(found);
Comments
Post a Comment