get one item from an array of name,value JSON

I know this question is old, but no one has mentioned a native solution yet. If you’re not trying to support archaic browsers (which you shouldn’t be at this point), you can use array.filter:

var arr = [];
arr.push({name:"k1", value:"abc"});
arr.push({name:"k2", value:"hi"});
arr.push({name:"k3", value:"oa"});

var found = arr.filter(function(item) { return item.name === 'k1'; });

console.log('found', found[0]);
Check the console.

You can see a list of supported browsers here.

In the future with ES6, you’ll be able to use array.find.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)