Skip to content

Instantly share code, notes, and snippets.

@runeb
Created April 5, 2021 19:20
Show Gist options
  • Save runeb/0e5e5fe31f293ccbc116394c40bbb59b to your computer and use it in GitHub Desktop.
Save runeb/0e5e5fe31f293ccbc116394c40bbb59b to your computer and use it in GitHub Desktop.
// Find all nested instances of _type `type`
const findAssets = (object, type, results = []) => {
if (object instanceof Object) {
if (object["_type"] === type) {
results.push(object);
return;
}
for (const key of Object.keys(object)) {
const value = object[key];
if (Array.isArray(value)) {
value.forEach((v) => findAssets(v, type, results));
} else if (value instanceof Object) {
findAssets(object[key], type, results);
}
}
}
return results;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment