javascript - JS - finding items in an array -
this question has answer here:
i have json feed (people.json) spits out following:
[ { "id":0, "firstname":"alison", }, { "id":1, "firstname":"fred", } ]
etc.
edit clarity**
i have var called searchterm
. in javascript how can find records in array firstname
matches searchterm
?
if looking object matches firstname
var json = [ { "id":0, "firstname":"alison", }, { "id":1, "firstname":"fred", } ]; function findbyname(name) { return json.find( function(f) { return f.firstname == name}); } console.log( findbyname('fred') );
Comments
Post a Comment