ES6 将字符串转换为对象数组 - JavaScript 代码示例
const sopNum = '"{"sop":"666","sop1":"1", "sop2":"2", "sop3":"3", "sop4":"4", "sop5":"5"}';\nconst sopObj = JSON.parse(sopNum);\nconst arr = [];\nfor (let i = 1; i <= 5; i++) {\n const label = SOP+${i};\n const name = sop${i};\n const obj = {\n label,\n name,\n [name]: sopObj[name]\n };\n arr.push(obj);\n}\nconst result = {\n arr,\n sop: sopObj.sop\n};\n\nconsole.log(result);
原文地址: https://www.cveoy.top/t/topic/qDvJ 著作权归作者所有。请勿转载和采集!