Get an item from JSON/Filter JSON

Hi,

Today I was working on JavaScript and I had a requirement to get one item from JSON object.
Here is the sample code for filtering.

var vJsonArr = [];

vJsonArr.push({ name: “k1”, value: “abc” });
vJsonArr.push({ name: “k2”, value: “def” });
vJsonArr.push({ name: “k3”, value: “ghi” });
var vfound = vJsonArr.filter(function (item) { return item.name === ‘k1’; });

Hope this helps.

Happy Coding

Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s