Skip to content

Instantly share code, notes, and snippets.

@haeramkeem
Created August 12, 2022 15:49
Show Gist options
  • Save haeramkeem/5d78c4f7b737d9996aaed4d083e85b70 to your computer and use it in GitHub Desktop.
Save haeramkeem/5d78c4f7b737d9996aaed4d083e85b70 to your computer and use it in GitHub Desktop.
JS) Init array
/* Source: https://velog.io/@kler/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EB%B0%B0%EC%97%B4-%EC%83%9D%EC%84%B1-%EC%B4%88%EA%B8%B0%ED%99%94-%ED%95%9C%EB%B2%88%EC%97%90-%ED%95%98%EA%B8%B0 */
/* console.log()로 v의 값을 확인해보면 undefined가 출력된다. */
const arr = Array.from({length: 5}, (v, i) => {
console.log(v, i)
return i;
});
// => undefined 0
// => undefined 1
// => undefined 2
// => undefined 3
// => undefined 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment