Let say I have a 3D array like this
[
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
]
How should i code to get any one of the value in this array?
1) You can use array indexing as:
const arr = [
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
];
const valueUsingMethod1 = arr[0][0];
console.log(valueUsingMethod1);
2) You can also use array-destructuring as
const arr = [
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
];
const [[valueUsingMethod2]] = arr;
console.log(valueUsingMethod2);
3) You can also use flat here
const arr = [
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
];
const [firstValue] = arr.flat(1);
console.log(firstValue);
Try this:
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>