We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// 拷贝a let a = [1,2] let b = [...a] // [1,2] // 字符串转数组 let str = 'hello' let arr = [...a] // ['h','e','l','l','e'] // 对象拷贝 let obj = {a:1,b:2} let newObj = {...obj} // {a:1,b:2}
let arr = [1,2] let newArr = arr.slice()
let arr = [1,2] let newArr = arr.concat()
JSON.parse(JSON.stringify(obj))
var c = [{a:1},{b:2}] var d = [...c.map(_ => ({...c}))]
copyArray(arr) { var newArr = arr.constructor === Array ? [] : {}; if (typeof arr !== 'object') { return; } for (var i in arr) { newArr[i] = typeof arr[i] === 'object' ? this.copyArray(arr[i]) : arr[i]; } return newArr; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
数组的浅拷贝
拓展运算符 (数组 字符串 对象皆可操作)
slice
concat
JSON序列化 不建议
数组的深拷贝
The text was updated successfully, but these errors were encountered: