How do I use an array for the Date() constructor argument?

Asked 1 years ago, Updated 1 years ago, 22 views

If I want the result of the function f2 to be the same as f1, can I solve this problem by adding a statement to f2?If such a solution is possible, what is an example of a solution?

let date;f1();f2();

function f1() {date=newDate(1970,0,1,0,0,0); console.log(date);}
// Thu Jan 01 1970 00:00 GMT+0900 (Japan Standard Time)

function f2(){
 constarray = [1970,0,1,0,0,0,0];
 date = new Date(array);
 console.log(date);
}
// Invalid Date

javascript

2022-09-30 16:45

1 Answers

For example, you can solve the problem by applying the spread syntax (comment suggestion).

date=newDate(...array);


2022-09-30 16:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.