JavaScript converts an array string into an array key-value pair, the implementation method is as follows?

Array: ["Frontend Development", "Mobile Development", "Sales"];

Original image:
insert image description here
Converted array key-value pair form:
insert image description here
the code is as follows:

let munm =["前端开发", "移动开发", "销售"];
let oarr = []; //建立空数组装数组键值对
for (let i = 0; i <= munm.length-1; i++) {
   console.log(i, munm[i])
   let job = {};
   job["id"] = i;
   job["jobs_name"] = munm[i];
   oarr.push(job)
};
//得到全部结果                                                                                                                                                                                   
console.log(oarr, '///');//转换成的数组键值对形式

Simply record it! Easy to check, less detours! ! !

Guess you like

Origin blog.csdn.net/weixin_46409887/article/details/128852829