简体   繁体   中英

Unable to Push multiple values array into keys array into a single Array using javascript

I have a Keys Array and Multiple Values Array . I want push values array into keys Array . Example :-

data[0] :['ktCalender', 'presenter', 'emailId', 'topic', 'status']             // Keys

[1] : ['2022-05-05', 'abc', 'abc@gmail.com', 'cricket overview', 'sheduled'] // Values [3]: ['2022-05-04', 'xyz', 'xyz@gmail.com', 'ApS', 'organized']. // Values

I want Answer like : [ {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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM