["c", "d", "e"] 我在想 slice 可以做到这一点,但是.. ["a","b","c","d","e"].s-6ren">
gpt4 book ai didi

javascript - 从 N 到最后一个元素的切片数组

转载 作者:IT王子 更新时间:2023-10-29 03:10:05 26 4
gpt4 key购买 nike

如何进行这种转变?

["a","b","c","d","e"] // => ["c", "d", "e"]

我在想 slice 可以做到这一点,但是..

["a","b","c","d","e"].slice(2,-1) // [ 'c', 'd' ]
["a","b","c","d","e"].slice(2,0) // []

最佳答案

不要使用第二个参数:

Array.slice(2);

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/slice

If end is omitted, slice extracts to the end of the sequence.

关于javascript - 从 N 到最后一个元素的切片数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14395050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com