With reference to question posted here use jQuery's find() on JSON object I have json object in which i'd like to search value of the element if i passed respective key element to it
Json:
{"RESPONSE":{"@xmlns":"","CODE":"0","SECODE":"0","TXNID":"17527","LASTBALANCE":"-12078.8","SURCHARGE":"2","CUSTOMERDETAILS":{"NAME":"Mr.ABC"}}}
I want to retrieve value Mr.ABC
when i passed Name
as a key to my function
Code:
console.log(getObjects(ContextObj, 'Name'));
function getObjects(obj, key) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (i == key) {
objects.push(obj);
}
}
return objects;
}
It gives output now as
[ ]