Skip to content

Instantly share code, notes, and snippets.

@gbitdev
Created July 16, 2021 09:45
Show Gist options
  • Select an option

  • Save gbitdev/389067d533e8157b6125870c3fd11f39 to your computer and use it in GitHub Desktop.

Select an option

Save gbitdev/389067d533e8157b6125870c3fd11f39 to your computer and use it in GitHub Desktop.
Deep key search
function findImages(page) {
let imagesArray = [];
JSON.stringify(page, (_, nestedValue) => {
if (nestedValue) {
if (nestedValue['images']) {
imagesArray = [...imagesArray, ...nestedValue['images']];
}
if (nestedValue['image']) {
imagesArray = [...imagesArray, nestedValue['image']];
}
}
return nestedValue;
});
return imagesArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment