Checking for Value in JS Object
- by pagewil
I have a JS Object like so:
var ob{
1 : {
id:101,
name:'john',
email:'[email protected]'
},
2 : {
id:102,
name:'jim',
email:'[email protected]'
},
3 : {
id:103,
name:'bob',
email:'[email protected]'
},
}
I want to check if this JS object already contains a record. If it doesn't then I want to add it. For example.
if(ob contains an id of 101){
//don't add john
}else{
//add john
}
Catch my drift? Pretty simple question. I just want to know the best way of doing it.
Thanks Guys!
W.