简体   繁体   中英

Coping Array(or variable) without the copy just being a reference to the original variable

I'm making a chess game in javascript and I wan't to make a copy of the board array so I can modify the board and easily restore it to it's a original state. I don't want to use J Query and have already tried to use slice(0) to copy the variable but that din't seem to work. Does anyone know how to copy an array(or variable for that matter)?

let array = [1,2,3,4,5,6,7]
let strArray = JSON.stringify(array)
let backup = JSON.parse(strArray)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM