const list1 = [1, 2, 3]
const list2 = [4, 5]

const mergedList = [...list1, ...list2]

console.log('Merged List: ', mergedList)

const obj1 = {a: 1, b: 2}
const obj2 = {c: 3}

const mergedObj = {...obj1, ...obj2}

console.log('Merged Object: ', mergedObj)

const weird1 = {...obj1, ...list2}
console.log('Merged list as object', weird1)

try {
  const weird2 = [...obj1, ...list1]
  console.log('Merged list as object', weird2)
} catch (e) {
  console.error('Failed merging an object to a list, reason: ', e.message)
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://codepen.io/livecodestream/pen/KKdEQYG