I hava a json object as
var arr=[{"id":"1","ref":"100"},{"id":"2","ref":"200"},{"id":"3","ref":"100"}]
Now I have a function such that a new json object is passed ex.{"id":"4","ref":"400"},then I need to search the arr[] whether there is any object with same ref or not.If there is no element with that ref ,then I need to push to arr.If else not.How can we do this
var arr = [];
var obj = {"id":"4","ref":"400"};
function(obj){
if(!arr.contains(obj.ref)) //this didn't work
{
arr.push(obj);
}
}
How can we check this condition whether there is an object with same ref in array.