Skip to content

Instantly share code, notes, and snippets.

View dr-mohamed-benkhalifa's full-sized avatar

Dr. Mohamed ben Khalifa dr-mohamed-benkhalifa

View GitHub Profile
@shakhal
shakhal / find_values.js
Last active January 27, 2023 22:52
Find values in JSON by key, recursively
function findValues(obj, key){
return findValuesHelper(obj, key, []);
}
function findValuesHelper(obj, key, list) {
if (!obj) return list;
if (obj instanceof Array) {
for (var i in obj) {
list = list.concat(findValuesHelper(obj[i], key, []));
}