動(dòng)漫人物
2022-07-01 16:48:52
這是我向數(shù)組添加元素的方式assets.push(house_location + " " + "Cost" + " " + cost + " " + "Downpay"+ " " + downpay)現(xiàn)在我正在尋找一種方法來(lái)從我的數(shù)組中刪除相同的特定元素。有人知道這個(gè)代碼嗎?所以基本上,與array.push相反
3 回答

冉冉說(shuō)
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊
如果要?jiǎng)h除最后推送的項(xiàng)目,請(qǐng)使用assets.pop()。如果你想像你說(shuō)的那樣刪除那個(gè)確切的項(xiàng)目,你可以這樣做:
assets.filter(d => d !== house_location + " " + "Cost" + " " + cost + " " + "Downpay"+ " " + downpay)

忽然笑
TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
我猜你正在尋找這些方法。
Array.shift() // Removes the first item from an array, and then returns the item removed.
Array.pop() // Removes the last item from an array, and then returns the item removed.
Array.splice() // I really can't be bothered to explain this one, so look at the link below.
添加回答
舉報(bào)
0/150
提交
取消