diff --git a/snippets/getImages.md b/snippets/getImages.md index bd3e2d364..6a291340d 100644 --- a/snippets/getImages.md +++ b/snippets/getImages.md @@ -1,11 +1,14 @@ --- title: getImages -tags: browser,beginner +tags: browser,intermediate --- -Fetches all images from within an element and puts them into an array +Fetches all images from within an element and puts them into an array. -- Use `Element.prototype.getElementsByTagName()` to fetch all `` elements inside the provided element, `Array.prototype.map()` to map every `src` attribute of their respective `` element, then create a `Set` to eliminate duplicates and return the array. +- Use `Element.getElementsByTagName()` to get all `` elements inside the provided element. +- Use `Array.prototype.map()` to map every `src` attribute of each `` element. +- If `includeDuplicates` is `false`, create a new `Set` to eliminate duplicates and return it after spreading into an array. +- Omit the second argument, `includeDuplicates`, to discard duplicates by default. ```js const getImages = (el, includeDuplicates = false) => {