How to loop through a javascript object and check each key exists in a separate multidimensional object

Posted by Paul Atkins on Programmers See other posts from Programmers or by Paul Atkins
Published on 2012-09-28T13:08:20Z Indexed on 2012/09/28 15:50 UTC
Read the original article Hit count: 213

Filed under:
|

I have 2 javascript objects and I am trying to loop through one object and check whether the key exists in a second multidimensional object going one level deeper each time.

Here are the two objects

var check = {'scope':'instance', 'item':'body', 'property': 'background'}; 

var values = {'instance': {'body' : {'background': '000000'}}};


b.map(check, function(key){

     console.log(values[key]);
});

How am I able to check 1 level deeper in the values object each time? What I am trying to do is check the values object as follows:

  • 1st values['instance']
  • 2nd values['instance']['body']
  • 3rd values['instance']['body']['background']

    Thanks

© Programmers or respective owner

Related posts about JavaScript

Related posts about jQuery