代码:
let Empjson = e.detail.value; //获取的对象 {"邱艺","邱艺2","1","1"}
let Emparr = []; //对象转成后的数组["邱艺","1","邱艺2","1"]
for (let i in Empjson) {
Emparr.push(Empjson[i])
}
console.log('转成数组:', Emparr);
let endarr = []; //将数组转为对象类型的数组
let length = Emparr.length;
for (let i = 0; i < length; i++) {
if (i % 2 == 0) { //每两个值一组
let js = {
emp_id: '',
emp_state: ''
}
js.emp_id = Emparr[i]; //第一个值
js.emp_state = Emparr[i + 1] //第二个值
endarr.push(js)
}
}
console.log('你最后得到对象:', endarr);