简体   繁体   中英

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?

[{x: "69", y: "104"},{x: "69", y: "109"},{x: "69", y: "300"}]

example I want remove x 69 and 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:

 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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM