Skip to content

Instantly share code, notes, and snippets.

@vijjusri14
Created February 20, 2020 06:08
Show Gist options
  • Select an option

  • Save vijjusri14/c93183e7fc4459a101fa52b61940df36 to your computer and use it in GitHub Desktop.

Select an option

Save vijjusri14/c93183e7fc4459a101fa52b61940df36 to your computer and use it in GitHub Desktop.
Find all indexes of the object in object array by matching object key using Jquery
var x = [{'key':'a'},{'key':'b'},{'key':'a'}];
$.fn.findAllIndexes = function(key,value) {
var result = [];
$(this).each(function(index,item){
if(item[key]===value){
result.push(index);
}
});
return result;
}
$(x).findAllIndexes('key','a');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment