0

I'm trying to grab a values from this nested object. Seems that the syntax is fine for the object. What am I missing?

console.log(thePosts['THE PARENT ONE']['sections']['ONE SECTION']['subs']['img'][3]);

window.thePosts = {}
window.thePosts = {
    'THE PARENT ONE' : {
        'url':'the-url',
        'sections': [{
            'ONE SECTION' : {
                'url':'making-money',
                'subs': [
                    {'_id:':'1','title': 'title 1','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
                    {'_id:':'1','title': 'title 2','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
                    {'_id:':'1','title': 'title 3','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
                    {'_id:':'1','title': 'title 4','img': '<img src="/wp-content/assets/images/pop1.jpg">'}
                ]
            },
            'TWO SECTION' : {
                'url':'marketing',
                'subs': [
                    {'_id:':'1','title': 'title 1','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
                    {'_id:':'1','title': 'title 2','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
                    {'_id:':'1','title': 'title 3','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
                    {'_id:':'1','title': 'title 4','img': '<img src="/wp-content/assets/images/pop1.jpg">'}
                ]
            }
        }]
    }
};
2
  • 1
    I am guessing you meant ['subs'][3]['img']? Commented Jul 30, 2013 at 17:46
  • 1
    thePosts['THE PARENT ONE']['sections'] is an array of objects! Commented Jul 30, 2013 at 17:50

2 Answers 2

2

Try this:

thePosts['THE PARENT ONE']['sections'][0]['ONE SECTION']['subs'][3]['img']

sections and subs are both arrays.

Sign up to request clarification or add additional context in comments.

Comments

2

sections is an array:

thePosts['THE PARENT ONE']['sections'][0]['ONE SECTION']['subs'][3]['img']
                                       ^                         ^----^

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.