本文介绍了从N到最后一个元素的切片数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何进行这种转换?

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

我当时以为 slice 可以做到这一点,但是..

I was thinking that slice can do this, but..

["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/zh-CN/docs/JavaScript/Reference/Global_Objects/Array/slice

这篇关于从N到最后一个元素的切片数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:36