So I have an array of objects, and I want to return an array of objects that have the imageUrl of ‘/front-cover’ as the prefix. I know I have to use a combination of the find function and a regex to match that pattern, however I suck at regex.
This is the inital array of Objects
[
{
"id":"template001",
"width":300,
"height":600,
"imageUrl":"/front-cover-portrait-1.jpg"
},
{
"id":"template002",
"width":300,
"height":600,
"imageUrl":""
},
{
"id":"template003",
"width":300,
"height":600,
"imageUrl":""
},
{
"id":"template004",
"width":300,
"height":600,
"imageUrl":"/back-cover-portrait.jpg"
},
{
"id":"template005",
"width":300,
"height":600,
"imageUrl":"/front-cover-portrait-2.jpg"
},
{
"id":"template006",
"width":600,
"height":300,
"imageUrl":"/front-cover-landscape.jpg"
},
{
"id":"template007",
"width":600,
"height":300,
"imageUrl":""
},
{
"id":"template008",
"width":600,
"height":300,
"imageUrl":"/back-cover-landscape.jpg"
}
]
I want to return this as a result
[
{
"id":"template001",
"width":300,
"height":600,
"imageUrl":"/front-cover-portrait-1.jpg"
}
{
"id":"template005",
"width":300,
"height":600,
"imageUrl":"/front-cover-portrait-2.jpg"
},
{
"id":"template006",
"width":600,
"height":300,
"imageUrl":"/front-cover-landscape.jpg"
}
]