收藏
回答

filePath.match()[0]后面的[0]是什么意思?

Quickstart里上传图片的函数有一段不太明白。

const filePath = res.tempFilePaths[0]
         
        // 上传图片
const cloudPath = 'my-image' + filePath.match(/\.[^.]+?$/)[0]

   

  wx.cloud.uploadFile({

          

     cloudPath,

      filePath,

       

     success: res => {...}



filePath.match(/\.[^.]+?$/)[0] 这里的[0]是什么意思呢?

回答关注问题邀请回答
收藏

2 个回答

  • 加肥猫
    加肥猫
    2019-11-02

    建议搜索

    String.prototype.match()


    2019-11-02
    有用 1
    回复 1
    • z.song
      z.song
      2019-11-02
      谢谢
      2019-11-02
      回复
  • o0o有脾气的酸奶
    o0o有脾气的酸奶
    2019-11-02

    string.match()返回的是一个数组对象

    a = filePath.match(/\.[^.]+?$/)

    filePath.match(/\.[^.]+?$/)[0] 就是 a[0]

    2019-11-02
    有用
    回复 1
    • z.song
      z.song
      2019-11-03
      谢谢
      2019-11-03
      回复
登录 后发表内容
问题标签