当前位置:网站首页>JSON in JS (launch object deep copy)
JSON in JS (launch object deep copy)
2022-07-28 05:16:00 【M78_ Domestic 007】
Full name :JavaScript Object Notation
JSON Is a string , A string format often used to transmit data over the network
Common string formats :
querystring Query string “name=karen&pwd=abc123&count=20"
template Template string `<div styLe="">666</div>`
JSON json character string ‘{"name " : " karen" , "its" : [ "heLLo" , "h5"]}’
JSON analysis
parse() Method Parse the string into objects
Anti parsing stringify() Parse the object into a string
Code display :
<script>
var re="JSON data "
var obj=JSON.parse(re)
console.log(re,obj)
//"JSON data " JSON data
var obj={name:"karen"}
console.log(obj)
//{name:"karen"}
var str=JSON.stringify(obj)
console.log(str)
//{"name":"karen"}
</script>Launch object deep copy 1( If there is no internal reference data or time regularity null Wait for data )
Ask for obj2 Object and the obj={name : "karen"} It looks the same , But they are not the same object , Can't write obj2={name : "karen"}
<script>
var obj={name:"karen"}
// Wrong way :
var obj2={}
obj2.name=obj.name
console.log(obj2,obj==obj2)//true
// It still points to the same memory space
// The right way :
var str=JSON.stringify(obj)//'{"name":"karen"}'
var obj2=JSON.parse(str)//{name:"karen"}
console.log(obj2,obj==obj2)//{name:"karen"} //false
</script>Object deep copy 2
<script>
function deepcopy(data){
if(typeof(data)=="object"){
if(data.constructor==Date){
return new Date(data.getTime())
}
else if(data==null){
return null
}
else if(data.constructor==RegExp){
return new RegExp(data)
}
else if(data.constructor==Array){
var newArray=new Array()
for(var i=0;i<data.length;i++){
var temp=data[i]
newArray.push(arguments.callee(temp))
}
return newArray
}
else{
var newobj=new data.constructor() //new Object()
// Object.keys()
for (var key in data) {
newobj[key]=arguments.callee(data[key])
}
return newobj
}
}
else{
return data
}
}
</script>边栏推荐
- Antd setfieldsvalue warning problem cannot use 'setfieldsvalue' until you use 'getfielddecorator' or
- SMD component size metric English system corresponding description
- Barbie q! How to analyze the new game app?
- How to simulate common web application operations when using testcafe
- FreeRTOS个人笔记-任务通知
- Implementation of simple upload function in PHP development
- [paper notes] - low illumination image enhancement - zeroshot - rrdnet Network - 2020-icme
- 【SLAM】LVI-SAM解析——综述
- RT_ Use of thread mailbox
- 【CVPR2022】On the Integration of Self-Attention and Convolution
猜你喜欢
![Classes and objects [medium]](/img/0a/955d00d63f06e7e15e946599628edf.png)
Classes and objects [medium]

为什么md5不可逆,却还可能被md5免费解密网站解密

Why is MD5 irreversible, but it may also be decrypted by MD5 free decryption website

微服务故障模式与构建弹性系统

Introduction to testcafe

The solution after the samesite by default cookies of Chrome browser 91 version are removed, and the solution that cross domain post requests in chrome cannot carry cookies

Analysis of the reason why easycvr service can't be started and tips for dealing with easy disk space filling

Driving the powerful functions of EVM and xcm, how subwallet enables Boca and moonbeam

go-zero单体服务使用泛型简化注册Handler路由

Online sql to XML tool
随机推荐
HDU 2586 How far away ? (LCA multiplication method)
Google browser cannot open localhost:3000. If you open localhost, you will jump to the test address
POJ 1330 Nearest Common Ancestors (lca)
Dcgan:deep volume general adaptive networks -- paper analysis
Duoyu security browser will improve the security mode and make users browse more safely
【ARXIV2204】Vision Transformers for Single Image Dehazing
FPGA: use PWM wave to control LED brightness
Barbie q! How to analyze the new game app?
Gym 101911c bacteria (minimum stack)
塑料可以执行GB/T 2408 -燃烧性能的测定吗
Comprehensively analyze the differences between steam and maker Education
HashSet add
Special topic of APP performance design and Optimization - poor implementation affecting performance
FPGA:使用PWM波控制LED亮度
分享几种管理C程序中标志位的方法
CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?
Autoreleasepool problem summary
从微服务基本概念到核心组件-通过一个实例来讲解和分析
【ARXIV2203】Efficient Long-Range Attention Network for Image Super-resolution
Can plastics comply with gb/t 2408 - Determination of flammability