Convert array of strings into an array of objects

前端 未结 5 1051
甜味超标
甜味超标 2020-11-30 14:40

I have this JavaScript array:

[ \"124857202\", \"500255104\", \"78573M104\" ]

I want to convert this particular array into an array of obje

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 15:23

    Use Array#map to convert each value into a different value:

    var newArr = arr.map(function(value) {
      return {name: value};
    });
    

    Array#map applies the callback to each element in the array and returns a new array containing the return values of the callback.

提交回复
热议问题