spread and rest operator javascript
function sum(...numbers) {
return numbers.reduce((accumulator, current) => {
return accumulator += current;
});
};
sum(1,2) // 3
sum(1,2,3,4,5) // 15var myName = ["Marina" , "Magdy" , "Shafiq"] ;const [firstName , ...familyName] = myName ;console.log(firstName); // Marina ;console.log(familyName); // [ "Magdy" , "Shafiq"] ;function sum(x, y, z) {
return x + y + z;
}
const numbers = [1, 2, 3];
console.log(sum(...numbers));
// expected output: 6
console.log(sum.apply(null, numbers));
// expected output: 6function myData(...args){console.log(args) ; // ["Marina",24,"Front-End Developer"]}myData("Marina",24,"Front-End Developer") ;
Also in JavaScript:
- js add style to each class
- javascript object first key
- react routing
- mongoose update subdocument by id
- Syntax Error: Thread Loader (Worker 0) .eslintrc.js: Environment key "es2021" is unknown at Array.forEach (<anonymous>)
- how to run cypress
- javascript format currency pt-br
- jquery is child of
- storybook react router
- call() vs apply() vs bind()
- javascript function from string
- html define javascript variable
- change a variable outside a function js
- convert an array to uppercase or lowercase js
- what is payload in redux
- react clear input value
- js require is not defined
- jquery select
- notify jquery
- reactjs javascript is mobile and desktop
- how to pass custom regex in jquery validation
- calculate rating out of 5
- A form label must be associated with a control react
- how to copy an arry react