๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Frontend/JavaScript

[ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(JavaScript) ] 2์ฐจ์› ๋ฐฐ์—ด ์ดˆ๊ธฐํ™” ํ•˜๊ธฐ

by YWTechIT 2021. 9. 27.
728x90

๐Ÿ“ 2์ฐจ์› ๋ฐฐ์—ด ์„ ์–ธํ•˜๊ธฐ

Array.from ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 2์ฐจ์› ๋ฐฐ์—ด์„ ์„ ์–ธ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 3ํ–‰ 4์—ด์„ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•œ 2์ฐจ์› ๋ฐฐ์—ด์„ ๋งŒ๋“ค๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•œ๋‹ค.

let row = 3;
let column = 4;
let arr = Array.from(Array(row), ()=> Array(column).fill(0));

console.log(arr)
๐Ÿ‘‰๐Ÿฝ [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]

 

reference

  1. MDN
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€