Created
April 5, 2021 19:20
-
-
Save runeb/0e5e5fe31f293ccbc116394c40bbb59b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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