Convert array of strings into an array of objects

前端 未结 5 1052
甜味超标
甜味超标 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:03

    Another approach - Array#reduce.

    var arr = ["124857202", "500255104", "78573M104"];
    var res = arr.reduce(function(s, a){
        s.push({name: a});
        return s;
      }, [])
      
    console.log(res);

提交回复
热议问题