Skip to content

Instantly share code, notes, and snippets.

View Rickgg's full-sized avatar
🎧
d-.-b

Ricardo Garza Rickgg

🎧
d-.-b
View GitHub Profile
@Rickgg
Rickgg / searchByKey.js
Created December 6, 2017 19:00
Function to recursively search an object by a key and returning the data found in the key.
function iterate (obj, key) {
var result;
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
// in case it is an object
if (property.match(RegExp(key, 'gi'))) {
return obj[property]; // returns the value
} else if (typeof obj[property] === "object") {
result = iterate(obj[property], key);
if (typeof result !== "undefined") {