JS 獲取陣列物件的值&提取Object的value

Hekiss發表於2024-05-17

示例

    let val = [{code: '230000', name: '黑龍江省'}, {code: '230100', name: '哈爾濱市'}]
    if (val.length > 0) {
      this.city = val.map(i => i.name) // ["黑龍江省", "哈爾濱市"]
      this.city = val.map(i => i.name).join('-')  // 獲取陣列物件的值為 黑龍江省-哈爾濱市
    }

相關文章