How to copy JS variables? [A novice, please give me some advice]
P粉668901898
P粉668901898 2023-06-28 17:54:37
0
2
536

On the query page, the copy button can only copy the content of the div above. How to copy the content below? ? ? please. . . . . .


##



111.png##

P粉668901898
P粉668901898

reply all (1)
WBOY

Shallow copy: Use `Object.assign()` or the spread operator `...` to copy an object, use `Array.from()` or the spread operator `...` to copy an array. For example:

let obj1 = { name: 'Alice', age: 20 }; let obj2 = Object.assign({}, obj1); // 浅拷贝对象 console.log(obj2); // 输出{ name: 'Alice', age: 20 } let arr1 = [1, 2, 3]; let arr2 = [...arr1]; // 浅拷贝数组 console.log(arr2); // 输出[1, 2, 3]

-Deep copy: Use `JSON.parse()` and `JSON.stringify()` to implement deep copy. For example:

let obj1 = { name: 'Alice', age: 20 }; let obj2 = JSON.parse(JSON.stringify(obj1)); // 深拷贝对象 console.log(obj2); // 输出{ name: 'Alice', age: 20 } let arr1 = [1, 2, [3, 4]]; let arr2 = JSON.parse(JSON.stringify(arr1)); // 深拷贝数组 console.log(arr2); // 输出[1, 2, [3, 4]]

  • reply Received, thank you very much for your help!
    P粉668901898 author 2023-06-29 20:35:51
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!