Reputation: 3
test_array = [ {"id":1,"title":"test1","type":"A" },
{"id":2,"title":"test2","type":"B" },
{"id":3,"title":"test3","type":"A" },
]
var x= test_array.isContain("type"=="B")
I want a method like I stated above and get an return value
Upvotes: 0
Views: 235
Reputation: 683
You can do something like this:
test_array = [ {"id":1,"title":"test1","type":"A" },
{"id":2,"title":"test2","type":"B" },
{"id":3,"title":"test3","type":"A" },
]
Array.prototype.isExist = function(key, value){
return this.some(function(obj){
return obj[key] === value;
});
};
test_array.isExist('type', 'B');
Upvotes: 1