簡體   English   中英

如何從數組中切片一個項目

[英]how to slice an item from an array

有人可以幫我一些離子代碼嗎?
我有一組使用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' }]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM