spread arguments javascript code example
Example 1: spread operator javascript
const parts = ['shoulders', 'knees'];
const lyrics = ['head', ...parts, 'and', 'toes'];
Example 2: spread operator
function sum(x, y, z) {
return x + y + z;
}
const numbers = [1, 2, 3];
console.log(sum(...numbers));
console.log(sum.apply(null, numbers));
Example 3: spread operator javascript
[a, b, ...objIteravel] = [1, 2, 3, 4, 5];
Example 4: js spread parameters
let list = ['a','b','c'];
let copy = [...list, 'd', 'e'];
function toDoList(...todos) {
document.write(
`<ul>${todos.map((todo) => `<li>${todo}</li>`).join("")}</ul>`
);
}
toDoList("wake up", "eat breakfast", ...list);