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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -