Thursday 18 August 2016

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

No comments:

Post a Comment