What does the three dots mean ... before document.querySelectorAll [duplicate]

2

In the following code, which means the three dots that precede document.querySelectorAll

const [marcas, valor] = [...document.querySelectorAll('input.classNew')];

marcas.addEventListener('keyup', function() {
    //codigo
} 
  

I did a lot of site and Google searches without success.

Note: I know that removing one or more specs gives an error in the script

    
asked by anonymous 18.07.2018 / 15:39

2 answers

0

This is a syntax of ES6 called operador spread .

  

Operador Spread

     

The spread operator allows an expression to be expanded in places where multiple arguments (by function calls) or multiple elements (by literal array) are expected.

Basically in your case it is used to define that the elements contained in array will be used 1 to 1 inside another array, assigning the first value to the variable marcas and following the variable valor .

    
18.07.2018 / 15:44
0

This is the Javascript Spread operator. You expand an expression where there are multiple arguments, for example:

function sum(a,b) {
    return a+b;
}

let myArray = [1, 2];
console.log(sum(...myArray)); //3

let spreadInArray = [3, 4, ... myArray];
console.log(spreadInArray); //[ 3, 4, 1, 2 ]
    
18.07.2018 / 15:44