Example of using the spread operator to combine two arrays:
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combinedArr = [...arr1, ...arr2];
console.log(combinedArr); // [1, 2, 3, 4, 5, 6]
Example of using the spread operator to add a new item to an array:
const oldArr = [1, 2, 3];
const newArr = [...oldArr, 4];
console.log(newArr); // [1, 2, 3, 4]
Example of using the spread operator to combine two objects into one:
const obj1 = { name: 'John', age: 30 };
const obj2 = { gender: 'male', profession: 'developer' };
const combinedObj = { ...obj1, ...obj2 };
console.log(combinedObj); // { name: 'John', age: 30, gender: 'male', profession: 'developer' }