Kevin Vella
Kevin Vella

Reputation: 1879

How can I use jquery .grep() to find an object then update it?

Im doing a simple algorithm which needs to get an object from a jquery key/value array, do some updates on it then replace the original object within the array with the updated object. How do I go about doing this?

What I have so far is the fetching of the object using grep:

 var country = $.grep(contentArray, function (e) { return e.key == countrykey; });

 country.value = 'Malta';

 //Need to replace old 'country' object in contentArray 

Thanks!

Upvotes: 4

Views: 10113

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

grep return an array

var country = $.grep(contentArray, function (e) { return e.key == countrykey; });
if(country && country.length == 1)
 country[0].value = 'Malta';

Upvotes: 11

Related Questions