Checking for Value in JS Object

Posted by pagewil on Stack Overflow See other posts from Stack Overflow or by pagewil
Published on 2011-01-04T21:47:41Z Indexed on 2011/01/04 21:53 UTC
Read the original article Hit count: 313

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery