Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

3 of 3
Commonmark migration

Here's what is happening with your code: you're accessing the first element of a JSON string, so my guess is you will get its first character: [.

You need to convert your string into an actual array before accessing it!

Use JSON.parse:

The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.

- MDN web docs

For example you can do:

const json = '[[{"firstname": "Micheal", "lastname": "Brown"}], [{"car": "Ford", "model": "Fiesta"}]]'
// that's what you have
console.log(json[0])
// that's what you want
array = JSON.parse(json)
console.log(array[0])

Ivan
  • 41.4k
  • 9
  • 78
  • 120

AltStyle によって変換されたページ (->オリジナル) /