天天看點

js動态定義變量

let a = null
let b = null      
let randomNum = Math.floor(Math.random() * 10)  // 0-9的随機整數

let map = {}

for(let i = 0; i < randomNum; i++) {
  let dynamicKey = `dynamic${i}`
  map[dynamicKey] = null //向map中動态添加
}      

繼續閱讀