Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

destructuring arrays with rest operator

// Rest operator on Arrays;
// It's usually shown as ...rest
// but you can name this what you like
// Think of it as "get the ...rest of the array"
const [q, r, ...callThisAnythingYouWant] = [1, 2, 3, 4, 5, 6, 7, 8];

console.log(q, r); // 1 2
console.log(callThisAnythingYouWant); // [ 3, 4, 5, 6, 7, 8 ]
Comment

Use Destructuring Assignment with the Rest Operator to Reassign Array Elements

const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
  "use strict";
  // change code below this line
  const [a,b,...arr] = list; // change this
  // change code below this line
  return arr;
}
const arr = removeFirstTwo(source);
console.log(arr); // should be [3,4,5,6,7,8,9,10]
console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to copy value instead of reference js 
Javascript :: axios send file 
Javascript :: js calculate distance between two coordinates 
Javascript :: how to clear state in react hooks 
Javascript :: add numbers in array 
Javascript :: Update multiple documents by id set. Mongoose 
Javascript :: converting strings to numbers 
Javascript :: js test if array 
Javascript :: forin js 
Javascript :: regex for comments javascript 
Javascript :: filter in array function 
Javascript :: ok that is something 
Javascript :: get left position based on container jquery 
Javascript :: play sound with keydown javascript 
Javascript :: duplicate numbers in an array javascript 
Javascript :: jquery nice select 
Javascript :: how to export a class in node js 
Javascript :: mongoose virtual 
Javascript :: js regex replace multiple matches 
Javascript :: p5js circle 
Javascript :: for loop set timeout 
Javascript :: click counter in js 
Javascript :: contains() js 
Javascript :: node.js util module 
Javascript :: how to know which button is clicked in jquery 
Javascript :: js get time 
Javascript :: alphabet to number javascript 
Javascript :: angular is not defined In AngularJS 
Javascript :: call a function multiple times 
Javascript :: js know size of screen displayed 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =