我具有从console.log(temp)
所示的动态生成的阵列:
[{user_id: "[email protected]", status: "Idle"}],
[{user_id: "[email protected]", status: "Busy"}]
我的代码:
this.scheduleService.getShiftSchedule().subscribe((temp)=>{
this.api = temp;
console.log(temp);
})
如何更改我的数组的格式变成像下面的阵列?
[[{id: 1,content: '[email protected]'},{id: 2,content: 'Idle'}],
[{id: 1,content: '[email protected]'},{id: 2,content: 'Busy'}]]
你可以通过采取通缉键及其id
的数组对象映射。
var data = [{ user_id: "[email protected]", status: "Idle" }, { user_id: "[email protected]", status: "Busy" }],
ids = [['user_id', 1], ['status', 2]],
result = data.map(o => ids.map(([key, id]) => ({ id, content: o[key] })));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
VAR =阵列JSON.parse( “[” +串+ “]”);
是ARR = [1,2,3,4,5,6,7,8,9]
var newArr = [];
while(arr.length) newArr.push(arr.splice(0,3));
console.log(newArr)
你可以尝试这样的