如何从数组中切片项目



有人可以帮我一些离子代码吗?
我有一个使用ngFor显示的项目数组。当用户单击某个项目时,该项目将被推送到另一个页面,该页面具有该项目的完整描述,并且具有完整的按钮。
当用户单击"完成"按钮时,应从原始数组中删除该项。我只是不知道如何从不同的组件中切片数组。请帮忙

我的理解是你想从数组中删除某个项目。这是对的吗?

在这种情况下,您可以使用如下例中的splice

let myArray = [{ a: 'firts', b: 'foo' },
{ a: 'second', b: 'bar' },
{ a: 'third', b: 'baz' }];
// to remove the third item from the array do this:
// first argument is the index of the item to remove
// second argument is the number of items to remove
myArray.splice(2, 1);
console.log(myArray) // [{ a: 'firts', b: 'foo' }, { a: 'second', b: 'bar' }]

最新更新