0

I have an array, that happens to be filled with arrays: [[1, "thing"], [2, "other thing"], [3, "still other thing"]] I want to be able to select a value inside one of the arrays without having to make the array a temporary variable and then pick the item. Can this be done?

Jonathan Spirit
  • 569
  • 3
  • 7
  • 14

1 Answers1

2

You can index into a nested array with the same '[]' syntax.

var arr = [[1, "thing"], [2, "other thing"], [3, "still other thing"]];
console.log(arr[0]); // [1, "thing"]
console.log(arr[0][0]); // 1

For reference, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

In that link search for two-dimensional

mrk
  • 4,999
  • 3
  • 27
  • 42