Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  197] [ 3]  / answers: 1 / hits: 27556  / 12 Years ago, thu, march 15, 2012, 12:00:00

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.


More From » jquery

 Answers
71

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


[#86816] Wednesday, March 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oswaldoh

Total Points: 109
Total Questions: 93
Total Answers: 113

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
;