Home » vue » if condition inside map or push or something else

if condition inside map or push or something else

Posted by: admin November 26, 2021 Leave a comment


as i am new in js, i need your help becuase i cant find any help anywhere else.

i have this array matchingAlbums


some are images and some are videos

without videos this code works fine

async fetch() {
  const matchingAlbums = await this.$strapi.find('albums', {
    slug: this.$route.params.slug,
  const images = []
  matchingAlbums[0].media.map((item) => {
    return images.push({
      thumb: `if mp4 then item.formats.large.url else item.url`
      width: item.width,
      height: item.height,
      src: item.url,
      mime: item.mime,

  this.album = matchingAlbums[0]
  this.images = images

but now that i have videos in my array, i need to change the thumb to the image path from item.formats.large.url where the mime is video/mp4

I tried doing if statement inside the map and push but it wont work.
I appreciate your help.


Use a ternary expression.

thumb: item.mime == 'video/mp4' ? item.formats.large.url : item.url,