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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With