Last active
November 14, 2019 13:59
-
-
Save iandesj/3db31aa6fa93811a941b7189add81cec to your computer and use it in GitHub Desktop.
Examples of Array.from() vs for loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const year = 2019; | |
const month = 10; // november, zero-indexed | |
const startDay = 14; | |
console.log('Array.from() example'); | |
const dateList = Array.from({length:7}, (val, idx) => { | |
return new Date(year, month, startDay + idx); | |
}); | |
console.log('dateList = ', dateList, '\n'); | |
console.log('for loop example'); | |
const dateListAgain = [] | |
for (let i=0; i < 7; i++) { | |
dateListAgain.push(new Date(year, month, startDay + i)); | |
} | |
console.log('dateListAgain = ', dateListAgain); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment