pass in array of integers to create new Date not working

Viewed 244

I have an array of integers that I want to create a new Date with by using new Date but how can i get rid of the brackets so im just passing in the list of numbers? I have this:

var array = [2015, 3, 18, 2, 0, 0]
var newdate = new Date(array) 

but it wont work because new Date cant have an array inside. Does anyone know how to make this work so im passing in:

var newdate = new Date(2015, 3, 18, 2, 0, 0) 

Thanks!

1 Answers

spread syntax does the trick.

var array = [2015, 3, 18, 2, 0, 0];
var newdate = new Date(...array);

console.log(newdate);

Related