我正在寻找一种方法来检索没有最后一个元素且不发生突变的数组。
_.remove
会改变数组并按值而不是索引进行搜索(即使它是 asked there )_.without
按值而不是索引搜索
我有 _.filter(array, function(el, i) { return i != array.length -1});
但是 siouf,不是很明确,它需要存储数组某处。
谢谢
最佳答案
我一直在寻找类似“butlast”的东西,但我找到了 initial
,它完成了这项工作:
var xs = [1, 2, 3, 4];
var xs2 = _.initial(xs);
console.log(xs, xs2); // [1, 2, 3, 4] [1, 2, 3]
关于javascript - Lodash:没有最后一个元素的数组,没有突变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36355635/