0

Lets say I have data structured like this

let array = [[1], [2], [3]]

and I want to use those elements as an index:

console.log(matrix[1][2][3])

Is there a way to break out those elements? I am trying to get the logic nailed down for n elements.

Here is what I have:

const getValue = (coords: []) => {
    let array = [];
    for (let i = 0; i < coords.length; i++) {
      array.push([coords[i]]);
    }

    console.log(complex[array]);
  };

But I get the error:

Type 'never[][]' cannot be used as an index type.ts(2538)
deadant88
  • 920
  • 9
  • 24
  • `output = coords.reduce((a,b) => a[b], complex)`. If the path could be invalid, then use `a?.[b]` – adiga Feb 13 '23 at 08:27

0 Answers0