How to get json object by javascript item -
so have array of json objects these below. retrieved using xmlhttp. want 'select' value name == "test" using javascript how do this? know can example data[0] not how want because id can change.
[ {"name" : "test", "value": "something"}, {"name" : "test2", "value": "something else"} ]
you can use loops this, can use array.filter
, can first match, ex.:
var items = [{"name" : "test", "value": "something"},{"name" : "test2", "value": "something else"}]; var = "name", = "test2" , select = items.filter(function(item){ return item[where] == is})[0]; console.log(select)
Comments
Post a Comment