有没有办法接收List
操作期间从splice()
中排除的元素? splice()
似乎返回一个新的List
,其中拼接的元素被排除在外,这是我根据API预期的结果,但我不确定如何获取我排除的元素。
const a: List<number> = List<number>([1, 2, 3, 4]),
b: List<number> = List<number>(a.splice(1, 1));
console.log(a.toArray()); // [1, 2, 3, 4]
console.log(b.toArray()); // [1, 3, 4]
// How would I get the hypothetical [2] that was excluded?
我认为splice()
会反映原生Array.splice()
或至少提供一些方法来同时获取新的List
和已移除的元素。
我是否必须使用slice()
然后splice()
将其分为两个步骤?
const a: List<number> = List<number>([1, 2, 3, 4]),
excluded: List<number> = List<number>(a.slice(1, 2)),
b: List<number> = List<number>(a.splice(1, 1));
console.log(a.toArray()); // [1, 2, 3, 4]
console.log(b.toArray()); // [1, 3, 4]
console.log(excluded.toArray()); // [2]
答案 0 :(得分:0)