Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

arrays

jquery

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!

like image 826
Kevin Vella Avatar asked Dec 21 '22 01:12

Kevin Vella


1 Answers

grep return an array

var country = $.grep(contentArray, function (e) { return e.key == countrykey; });
if(country && country.length == 1)
 country[0].value = 'Malta';
like image 75
Arun P Johny Avatar answered Mar 17 '23 00:03

Arun P Johny