Skip to content

Instantly share code, notes, and snippets.

@Ketcap
Last active May 2, 2018 07:58
Show Gist options
  • Save Ketcap/38ff0670f834ef6a56e30d9f49b23798 to your computer and use it in GitHub Desktop.
Save Ketcap/38ff0670f834ef6a56e30d9f49b23798 to your computer and use it in GitHub Desktop.
Checking given name of array if it exists inside object or not
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