Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove item from json object

I have the following json object that im iterating through:

obj = { '19': { id: '19', price: 5.55},
      '20': { id: '20', price: 10.00} }

$.each(obj, function(index, value){
  if(value.price < 5)
  {
   delete obj[index];
  }     

});

I just want to delete an item from the object under certain conditions. In this case, if the price is less than 5.

I've tried delete, but it doesn't do anything.

like image 474
dzm Avatar asked Mar 15 '12 21:03

dzm


1 Answers

Works fine, if the value is < 5. In your case the value is 5.55 which is > 5

DEMO - To show the object got deleted when the value is < 5

like image 55
Selvakumar Arumugam Avatar answered Nov 09 '22 22:11

Selvakumar Arumugam