[英]How do I remove multiple array elements in Javascript?
I have an array of elements in Ruby [2,4,6,3,8]
I need to remove array with value, How do I do that? 我在Ruby
[2,4,6,3,8]
有一个元素数组,我需要删除带值的数组,我该怎么做?
[{x: "69", y: "104"},{x: "69", y: "109"},{x: "69", y: "300"}]
example I want remove x 69 and y 109 例如我要删除x 69和y 109
Try this example , use filter (Array prototype method). 试试这个例子,使用过滤器(数组原型方法)。
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);
use filter
on the object to filter the object not having those x
and y
values: 在对象上使用
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.