Created
February 20, 2020 06:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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