无法使用 javascript 将多个值数组推送到键数组到单个数组中
Unable to Push multiple values array into keys array into a single Array using javascript
我有一个键数组和多值数组。我想将 values array 推入 keys Array 。
示例:-
data[0] :['ktCalender', 'presenter', 'emailId', 'topic', 'status'] // Keys
[1] : ['2022-05-05', 'abc', 'abc@gmail.com', 'cricket overview', 'sheduled'] // 值
[3]:['2022-05-04', 'xyz', 'xyz@gmail.com', 'ApS', 'organized']。 // 值
我想要这样的答案:[
{ktCalender:2022-05-05,presenter:'abc',emailId:'abc@gmail.com',topic:'cricket overview',status:'sheduled'},
ktCalender:'2022-05-04',presenter:'xyx',emailId:'xyz@gmail.com',topic:'APS',status:'organized'},
]
let data = ['ktCalender', 'presenter', 'emailId', 'topic', 'status'];
let Values = [];
Values[0] = ['2022-05-04', 'xyz', 'xyz@gmail.com', 'ApS', 'organized'];
Values[1] = ['2022-05-05', 'abc', 'abc@gmail.com', 'cricket overview', 'sheduled']
let result = [];
Values.forEach((val) => {
const obj = data.reduce((accumulator, element, index) => {
return {...accumulator, [element]: val[index]};
}, {});
result.push(obj);
});
console.log(result);
我有一个键数组和多值数组。我想将 values array 推入 keys Array 。 示例:-
data[0] :['ktCalender', 'presenter', 'emailId', 'topic', 'status'] // Keys
[1] : ['2022-05-05', 'abc', 'abc@gmail.com', 'cricket overview', 'sheduled'] // 值 [3]:['2022-05-04', 'xyz', 'xyz@gmail.com', 'ApS', 'organized']。 // 值
我想要这样的答案:[ {ktCalender:2022-05-05,presenter:'abc',emailId:'abc@gmail.com',topic:'cricket overview',status:'sheduled'}, ktCalender:'2022-05-04',presenter:'xyx',emailId:'xyz@gmail.com',topic:'APS',status:'organized'},
]
let data = ['ktCalender', 'presenter', 'emailId', 'topic', 'status'];
let Values = [];
Values[0] = ['2022-05-04', 'xyz', 'xyz@gmail.com', 'ApS', 'organized'];
Values[1] = ['2022-05-05', 'abc', 'abc@gmail.com', 'cricket overview', 'sheduled']
let result = [];
Values.forEach((val) => {
const obj = data.reduce((accumulator, element, index) => {
return {...accumulator, [element]: val[index]};
}, {});
result.push(obj);
});
console.log(result);