if condition inside map 或 push 或其他东西

if condition inside map or push or something else

因为我是 js 的新手,我需要你的帮助,因为我在其他任何地方都找不到任何帮助。

我有这个数组matchingAlbums

[
   {
      "id":6,
      "title":"Album1",
      "slug":"album1",
      "media":[
         {
            "id":156,
            "name":"image1.jpg",
            "width":2048,
            "height":2048,
            "hash":"image1_d556c8283b",
            "ext":".jpg",
            "mime":"image/jpeg",
            "size":273.98,
            "url":"/uploads/image1_d556c8283b.jpg",
         },
         {
            "id":157,
            "name":"video1.mp4",
            "width":640,
            "height":1202,
            "formats":{
               "thumbnail":{
                  "ext":".png",
                  "mime":"image/png",
                  "width":83,
                  "height":156,
                  "size":31.45,
                  "url":"/uploads/thumbnail_video1.png"
               },
               "large":{
                  "ext":".png",
                  "mime":"image/png",
                  "width":532,
                  "height":1000,
                  "size":647.84,
                  "url":"/uploads/large_video1.png"
               },
               "medium":{
                  "ext":".png",
                  "mime":"image/png",
                  "width":399,
                  "height":750,
                  "size":430.94,
                  "url":"/uploads/medium_video1.png"
               },
               "small":{
                  "ext":".png",
                  "mime":"image/png",
                  "width":266,
                  "height":500,
                  "size":230.47,
                  "url":"/uploads/small_video1.png"
               }
            },
            "ext":".mp4",
            "mime":"video/mp4",
            "url":"/uploads/video1.mp4",
         }
      ]
   }
]

有些是图片,有些是视频

没有视频此代码工作正常

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
},

但现在我的数组中有视频,我需要将 thumb 更改为从 item.formats.large.url 开始的图像路径,其中 mime 是 video/mp4

我尝试在地图中执行 if 语句并推送,但它不起作用。 感谢您的帮助。

使用三元表达式。

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