What do the three dots mean ... before Document.querySelectorAll

Asked

Viewed 716 times

2

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

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

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

I did numerous searches on the site and Google without success.

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

  • 1

    @Andersoncarloswoss, thank you!!!!

  • I affirmed the question and denied the two answers, I believe that voting as duplicate is the best action in this "good" question

  • The main advantage is to be able to copy the array instead of passing the reference.

  • @Marceloboni, after @ Andersoncarloswoss pointed out the links I was going to remove the question but the answers won’t let me remove.

  • @Marceloboni it’s cool that you read "when to negative an answer" which clearly says that you should only negative when the answer is dangerously wrong. Attitudes such as that taken in this case demotivate to respond. Here you give an explanation of when you should vote against.

  • @Sorack the answer is not wrong, but end up taking the merit of the other answers (I may be wrong and may even be exaggerated), I believe that linking the other answers to this question and closing it as duplicate may be the best in this case (Again, it may be an exaggeration on my part)

  • @Marceloboni yes, it is exaggeration and the wrong way to use the downvote, as you can read in what I Linkei. I will emphasize here "Use the votes against when you find a remarkably sloppy and sloppy publication or an answer that is clearly, and perhaps dangerously, incorrect". And also "Votes against should be reserved for extreme cases".

  • Downvote is a thing of super lazy genius. You know damn well, you find your question/answer incorrect but I do not present arguments. In my case, of this question, he must have felt that I had an obligation to know about this operator or maybe he didn’t see my difficulty Fiz inúmeras buscas no site e no Google sem obter exito.

Show 4 more comments

2 answers

0

It’s 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 ]

0


This is a syntax of ES6 calling for operador spread.

Operador Spread

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

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

  • 2

    O basicamente no seu caso .... utilizados 1 a 1 dentro de outro array was decisive for me to understand clearly the meaning of Operador Spread

Browser other questions tagged

You are not signed in. Login or sign up in order to post.