[英]How to map to an object using the values of an array of object?
嗨,我有以下 json 響應
[{ country: string, code: string}]
現在我想用array.map(x => {[x.country]: false})
創建一個對象,只有語法[]
使用 country 的值作為鍵不起作用。 目的是從后端獲取一個動態復選框組 如何將數組映射到{ "country": false }
箭頭后面的括號屬於函數,而不屬於您嘗試創建的對象。
添加任一 ()
array.map(x => ({[x.country]: false}))
或返回值。
array.map(x => {
return {[x.country]: false};
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.