【问题标题】:How to slice a two dimensional array? [duplicate]如何对二维数组进行切片? [复制]
【发布时间】:2021-01-29 03:32:31
【问题描述】:

我有一个数组说

arr1 = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]

我想切片并选择第二列和第三列。

我尝试过使用 slice,但没有成功。

var result = arr1.slice(1,3);

但我没有得到应有的输出

[[2,3],[6,7],[10,11]]

是因为我使用 Google 电子表格收集数据吗?

【问题讨论】:

  • 非常抱歉我的意思是专栏

标签: javascript google-apps-script


【解决方案1】:

您需要映射切片数组。

const
    array = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],
    customSlice = array => array.slice(1, 3),
    result = array.map(customSlice);
    
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 2013-06-21
    • 2020-08-07
    • 2013-04-12
    相关资源
    最近更新 更多