0

If I log the following data structure I get the output below:

console.log(businessDetails[8])

[ 
  { businessDetails: 
       { companyName: 'Companyname' },
    _id: 'LrqSm5LJcxpo5wW7W' 
  } 
]

How can I access the companyName field?

I would've thought that I could do it like this:

console.log(businessDetails[8].businessDetails.companyName)

Unfortunately this doesn't work.

What do I need to do to access this element?

1 Answer 1

1

maybe: console.log(businessDetails[8][0].businessDetails.companyName)

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

1 Comment

That worked, the problem I've got is that it doesn't work in a loop so I'll need to try something else. After the loop runs this code works fine.

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.