SpreadOperator

mail@pastecode.io avatar
unknown
markdown
2 months ago
569 B
3
Indexable
Never

Spread Operator

On Objects, you can use the spread operator to merge two objects or to replace one or more attributes of an object.

const person = { age: 30, name: 'sam', email: 'espinoza.jimnez@gmail.com' } const updatedPersonsAge = { ...person, age: 34 } console.log(updatedPersonsAge)

On Arrays, you can use the spread operator to merge two arrays or to add an alement to an array.

const fruits = ['pear', 'apple'] const moreFruits = ['orange', 'banana'] const basquet = [...fruits, ...moreFruits] console.log(basquet)
Leave a Comment