假設我有一個像這樣的 3D 陣列
[
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
]
我應該如何編碼以獲取此陣列中的任何一個值?
uj5u.com熱心網友回復:
1)您可以將陣列indexing用作:
const arr = [
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
];
const valueUsingMethod1 = arr[0][0];
console.log(valueUsingMethod1);
2)您也可以array-destructuring用作
const arr = [
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
];
const [[valueUsingMethod2]] = arr;
console.log(valueUsingMethod2);
3)你也可以flat在這里使用
const arr = [
[
[3.12234, 50.12322],
[3.12332, 12.12323],
[3.431232, 122.22317],
],
];
const [firstValue] = arr.flat(1);
console.log(firstValue);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/340934.html
標籤:javascript 数组 打字稿
下一篇:將物件鍵映射到泛型類中的值型別
