Digamos que tengo una matriz 3D como esta
[ [ [3.12234, 50.12322], [3.12332, 12.12323], [3.431232, 122.22317], ], ]¿Cómo debo codificar para obtener cualquiera de los valores en esta matriz?
1) Puede usar la indexing de matrices como:
const arr = [ [ [3.12234, 50.12322], [3.12332, 12.12323], [3.431232, 122.22317], ], ]; const valueUsingMethod1 = arr[0][0]; console.log(valueUsingMethod1); 2) También puede usar array-destructuring como
const arr = [ [ [3.12234, 50.12322], [3.12332, 12.12323], [3.431232, 122.22317], ], ]; const [[valueUsingMethod2]] = arr; console.log(valueUsingMethod2); 3) También puedes usar flat aquí
const arr = [ [ [3.12234, 50.12322], [3.12332, 12.12323], [3.431232, 122.22317], ], ]; const [firstValue] = arr.flat(1); console.log(firstValue);Prueba esto:
var test = [ [ [3.12234, 50.12322], [3.12332, 12.12323], [3.431232, 122.22317], ], ] var open = test[0] // get the array [2] // get either [3.12234, 50.12322], [3.12332, 12.12323], or [3.431232, 122.22317] [1] // get item [0] or [1] from each value console.log(open); <body> </body>