[英]How do I remove multiple array elements in Javascript?
我在Ruby [2,4,6,3,8]
有一個元素數組,我需要刪除帶值的數組,我該怎么做?
[{x: "69", y: "104"},{x: "69", y: "109"},{x: "69", y: "300"}]
例如我要刪除x 69和y 109
試試這個例子,使用過濾器(數組原型方法)。
var ARRAY = [{x: "69", y: "104"},{x: "69", y: "109"},{x: "69", y: "300"}] .filter(function(item){ return item.x==="69" && item.y==="109"; }); console.log(ARRAY);
在對象上使用filter
過濾不具有x
和y
值的對象:
var arr = [{'x': "69", 'y': "104"},{'x': "69", 'y': "109"},{'x': "69", 'y': "300"}]; var removeX = '69', removeY = '109'; var res = arr.filter((obj)=> (obj.x !== removeX || obj.y !== removeY)); console.log(res);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.