I am trying to filter through an array of objects to find all values with an image extension then push the values found into their own array.
Example: imageArray = ["steve.jpg", "funimage1.jpg", "coolimage2.png","greatimage3.svg", "jimmysavatar.jpg" ...]
.
Here is a jsfiddle to test: https://jsfiddle.net/25pmwsee/
const myArray = [{
"prepend": false,
"name": "steve",
"avatar": "steve.jpg",
"imgs": [
"funimage1.jpg",
"coolimage2.png",
"greatimage3.svg"
]
},
{
"prepend": false,
"name": "jimmy",
"avatar": "jimmysavatar.jpg",
"imgs": [
"realimage1.jpg",
"awesomeimage2.png",
"coolimage3.svg"
]
}]
const extensions = [".jpg", ".png", ".svg"];
let imageArray = [];
// search in array for extension then push key to array
for (let i = 0; i < extensions.length; i++) {
if ( extensions[i] in myArray ) {
imageArray.push(image)
}
}