[removed] get subarray from an array by indexes

前端 未结 4 1313
执笔经年
执笔经年 2021-01-03 05:51

Is there a one-line code to get an subarray from an array by index?

For example, suppose I want to get [\"a\",\"c\",\"e\"] from [\"a\",\"b\",\"c\"

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 06:36

    You can use a combination of Array#filter and Array#includes

    const array = ['a','b','c'];
    console.log(array.filter((x,i) => [0,2].includes(i)));

提交回复
热议问题