Last active
May 2, 2018 07:58
-
-
Save Ketcap/38ff0670f834ef6a56e30d9f49b23798 to your computer and use it in GitHub Desktop.
Checking given name of array if it exists inside object or not
This file contains 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
const obj = { | |
a: [], | |
b: { | |
c: [1], | |
q: 'asd', | |
d: { | |
h: 'asd', | |
g: 'sd', | |
e: { | |
f: [] | |
} | |
} | |
}, | |
k: { | |
s: [] | |
} | |
}; | |
export function check_is_array(object, array_name) { | |
const keys = Object.keys(object) | |
let isFound = keys.indexOf(array_name) > -1; | |
if (isFound && object[array_name].constructor === Array) { | |
return true; | |
} | |
return keys.some((key) => { | |
let found = false; | |
if (object[key].constructor === Object) { | |
found = check_is_array(object[key], array_name); | |
}; | |
return found; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment