JS : Convert Array of Strings to Array of Objects

前端 未结 1 1723
渐次进展
渐次进展 2020-11-27 08:22

i have this array of strings :

let myArray : [\"AA\",\"BB\" , \"CC\" ...]

I want to convert it to an array of obje

相关标签:
1条回答
  • 2020-11-27 08:59

    You can use .map() for this. It passes the index into the callback.

    myArray = myArray.map((str, index) => ({ value: str, id: index + 1 }));
    
    0 讨论(0)
提交回复
热议问题