// if using a forEach() to associate each key-value pairs into an array of objects
function combiningArraysIntoKeyPairValues() {
var arr1 = 'declare your first array here';
var arr2 = 'declare your second array here';
// ps: you must consider that both array has same length?
var combinedObj = {};
let arr = [];
arr1.forEach((item, index) => {
combinedObj = { name: item, amount: arr2[index] };
arr.push(combinedObj);
});
return arr;
}
console.log(combiningArraysIntoKeyPairValues());
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter