Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript spread and rest operator

let array1 = ["one", "two", "three", "four"]
let array2 = ["five", "six", "seven"]

// Spread operator
let finalArray = [...array1, ...array2]
console.log(finalArray)
// output: ["one", "two", "three", "four", "five", "six", "seven"]

// rest operator
let [first, ...rest] = array1
console.log(first) //output:  one
console.log(rest)  // output: ["two", "three", "four"]
 
PREVIOUS NEXT
Tagged: #javascript #spread #rest #operator
ADD COMMENT
Topic
Name
8+3 =