let a = [1,2,3] let b = a b[0] = 0 console.info(b) //-> [0, 2, 3] console.info(a) // コピー元も変わる //-> [0, 2, 3] let c = a.concat() // 配列をコピー c[0] = 100 console.info(c) //-> [100, 2, 3] console.info(a) //-> [0, 2, 3]
牌語備忘録 -pygo
let a = [1,2,3] let b = a b[0] = 0 console.info(b) //-> [0, 2, 3] console.info(a) // コピー元も変わる //-> [0, 2, 3] let c = a.concat() // 配列をコピー c[0] = 100 console.info(c) //-> [100, 2, 3] console.info(a) //-> [0, 2, 3]