const testObj = { name: 'David', movie: 'fight club', active: true, }; const testObj2 = { name: 'kevin', movie: 'Bladerunner', active: false, }; // using rest only const combined = []; //empty array function makeArrayFromMUtipleObjects(...args) { for (let item of args) { // will have two separate objects combined.push(item); // push into the empty arry } } console.log(combined); // using rest and another param const anotherArray = []; function makeArray(array, ...itemsToAdd) { return array.concat(itemsToAdd); } const made = makeArray(anotherArray, testObj, testObj2); console.log(made);
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