0

I have an array where are objects. Here's one example::

color:"rgb(235, 75, 75)"
id:"6912128558"
img:""
name:"AWP | Dragon Lore (Factory New)"
price:"1852.2"

If I would forEach loop that array and if price >= with total, then it's going to remove the full object. I hope it makes sense.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Aleks Kpur
  • 121
  • 1
  • 2
  • 11

1 Answers1

1

You can create a new array by filtering the objects you want to keep

var cheapObjects = allObjects.filter(o => o.price < total); // whatever "total" is

or the legacy equivalent

allObjects.filter(function(o) { return o.price < 1000 })

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

Phil
  • 157,677
  • 23
  • 242
  • 245