Spread
Array Spread
const itemList = [1, 2, 3];
const additionalItemList = [5, 6];
const newItemList = [...itemList, 4, ...additionalItemList];
console.log(newItemList); // [1, 2, 3, 4, 5, 6]
Object Spread
Très pratique pour respecter l'immutabilité.
const user = {
firstName: 'Foo',
lastName: 'BAR',
email: '[email protected]'
};
const newUser = {
...user,
email: '[email protected]',
phoneNumber: '+6 12 34 56 78'
};
console.log(newUser);
// {
// firstName: 'Foo',
// lastName: 'BAR',
// email: '[email protected]',
// phoneNumber: '+6 12 34 56 78'
//}
Dernière mise à jour