1

I’m new to coding and slef teaching JavaScript. My task I was set was to identify the largest value in an array.

My soloition works, but I needed the ‘...’ for it to work properly.

My question is, what does the ‘...’ in the last line actually mean/do?

function createAnArr(){
let myArr = prompt("Enter your numbers separated by commas:").split(",");
return myArr; 
}

console.log(Math.max(...createAnArr()));
  • 2
    Also, probably a bit more accurate https://stackoverflow.com/questions/41862243/what-means-in-javascript-es6?noredirect=1&lq=1 although the answer from the other thread seems apt. – VLAZ Sep 25 '18 at 22:14

1 Answers1

1

'...' it means it will be able to take any number of arguments of the respective scope

'...': The spread operator is used for array construction and destructuring, and to fill function arguments from an array on invocation. A case when the operator spreads the array (or iterable object) elements.

more details you can see here

Mahamudul Hasan
  • 2,745
  • 2
  • 17
  • 26