Loop date and push date to an array

Hi guys,
Very simple code I would expect to work different:
I would like to push dates to an array within the following loop.
I thought I will get the same result for the test array as in the console.log(date) but see what I get???
What is it, I am doing wrong here?

export async function button11_click(event) {
let test =
let date = new Date();
let enddate = new Date()
enddate.setDate(date.getDate() + 30);
while (date < enddate) {
test.push(date)
console.log(date)
date.setDate(date.getDate() + 5)
}
console.log(test)
}

Already answered (but it got deleted) that instead of:

 test.push(date)//wrong as it passes a reference only

you should use:

  test.push(new Date(date)); 

Thanks a lot J.D. these small changes make the difference but sometimes really hard to follow for a beginner like me! – But learning though!
j Florian

@fzupan you’re welcome

That’s stupid, why are messages getting removed again, did when we had that spam episode, however shouldn’t be happening now.

Anyways, thanks for reposting J. D. :+1:

thank you J.D and Florian - your post just saved me hours of hair tearing!! :slight_smile: