Created
June 9, 2021 08:23
-
-
Save thisiskhan/27ad87a7b7367dccf40c46060d657156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Spread & Rest Operators | |
/* | |
Spread: Used to split up arrow elements OR object properties. | |
const nnewarray = [...oldArray, 1,2] | |
const newObject = {...oldObject, newProp:5} | |
Rest: Used to merge a lost of functions argumnets into array. | |
function sortArray(...arg){ | |
return args.sort() | |
} | |
*/ | |
// Spread Operator. | |
const numbers = [1, 2, 3 ]; | |
const newNumbers = [...numbers, 4]; | |
console.log(newNumbers); | |
/* | |
Output: [ 1, 2, 3, 4 ] | |
*/ | |
const person = { | |
name : "Raza Khan" | |
} | |
const newPerson = { | |
...person, | |
age : 18, | |
} | |
console.log(newPerson.name, newPerson.age); | |
/* | |
Output: Raza Khan 18 | |
*/ | |
// Rest Operator | |
const filter = (...args) => { | |
return args.filter(el => el === 1); | |
} | |
console.log(filter(1, 2, 3)); | |
/* | |
Output: [ 1 ] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment