Sunday, 6 September 2020

How to filter JSON data to get value based on the supplied key?

 var existingData = [];


some-loop{

    existingData.push(
{
'email' : $(this).attr("ows_Email_x0020_ID"), //this will be the key
'id' : $(this).attr("ows_ID") // record id for a given email will be fetched
}
}


function getIDbyEmail(emailID)
{
try
{
//var obj; = existingData.filter(i=>i.email==emailID);

var obj = existingData.filter(function(item){
    return item.email == emailID;
});

var _id = obj[0].id;

if(_id == undefined || _id == "" || _id == null)
{
return 0;
}
else
{
return _id;
}
}
catch(err)
{
return 0;
}
}





No comments:

Post a Comment