samedi 4 avril 2015

How to check if object exist by Id in tab of json object?

I have an array of objects:



var tab = [
{
"id": "1",
"data" : "blabla"
},
{
"id": "2",
"data": "samplesample"
}
]


Are there any simple tools for check if an object exist in this array by id.


Something like :



chekexists(tab, "id", "1") ; // return true
chekexists(tab, "id", "2") ; // return true
chekexists(tab, "id", "3") ; // return false
chekexists(tab, "data", "blabla") ; // return true
chekexists(tab, "data", "toto") ; // return false


Is this possible to perform this with underscore?


For avoid confusion, my tab is load like this :



var tab = JSON.parse(fs.readFileSync('path'));

Aucun commentaire:

Enregistrer un commentaire