I have this array:
var arr = [];
arr.push({name:"k1", value:"abc"});
arr.push({name:"k2", value:"hi"});
arr.push({name:"k3", value:"oa"});
is it possible to do get the value or a specific element by knowing the name ?
something like this:
arr['k2'].value
or
arr.get('k1')
Arrays are normally accessed via numeric indexes, so in your example
arr[0] == {name:"k1", value:"abc"}. If you know that thenameproperty of each object will be unique you can store them in an object instead of an array, as follows:If you actually want an array of objects like in your post you can loop through the array and return when you find an element with an object having the property you want: