如何从数组中删除元素-Javascript P5



这是我向数组添加元素的方法

assets.push(house_location + " " + "Cost" + " " + cost + " " + "Downpay"+ " " + downpay)

现在,我正在寻找一种方法,从数组中删除相同的特定元素。有人知道这个代码吗?所以基本上,与array.prush 相反

您要查找的是拼接方法。

如果你想删除你推送的最后一个项目,请使用assets.pop((。如果你想像你说的那样删除那个项目,你可以这样做:

assets.filter(d => d !== house_location + " " + "Cost" + " " + cost + " " + "Downpay"+ " " + downpay)

我猜您正在寻找这些方法。

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.

拼接方法。

最新更新