0

I would like to know the best method for grabbing values from nested objects like this one:

var object = {
    1: {
        1: {
        "names": "bob"
        },
        2: {
        "names": "jim"
        }
    }
}

What function or loop would I write to push the values “bob” and “Jim” into an array?

Thank you in advance!

1 Answers1

0

you can use Object.values + map

Object.values(object[1]).map(p => p.names)
albert
  • 464
  • 2
  • 7
  • You're assuming that the top-level object only has one property that's always `object[1]`. That seems unlikely. – Barmar Mar 12 '20 at 03:21