Skip to content

Commit e378778

Browse files
authored
Merge pull request #16 from suyashvash/main
Added getElementByKeyValue
2 parents 14f1d2e + e233ff2 commit e378778

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ function sort_nums(arr, reverse = false) {
163163
}
164164
}
165165

166+
/**
167+
* To get all the elements of an array with given key and value.
168+
* More like Where claus in php just for js array
169+
*
170+
*
171+
* @param array arr
172+
* @param string key
173+
* @param string value
174+
* @param number value
175+
* @returns array
176+
*/
177+
178+
function getElementByKeyValue(arr,key,value){
179+
return arr.filter(item=>item[key]==value)
180+
}
181+
166182
export {
167183
is_array,
168184
is_num_array,
@@ -178,4 +194,5 @@ export {
178194
array_sum,
179195
array_slice_sum,
180196
sort_nums,
197+
getElementByKeyValue,
181198
};

0 commit comments

Comments
 (0)