当前位置:网站首页>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>边栏推荐
- How to simulate common web application operations when using testcafe
- Pipe /createpipe
- HDU 2874 connections between cities
- 数据库日期类型全部为0
- [high CPU consumption] software_ reporter_ tool.exe
- App test process and test points
- What is the reason why the easycvr national standard protocol access equipment is online but the channel is not online?
- RT_ Use of thread message queue
- FreeRTOS personal notes - task notification
- Barbie q! How to analyze the new game app?
猜你喜欢

【CVPR2022】On the Integration of Self-Attention and Convolution
![[high CPU consumption] software_ reporter_ tool.exe](/img/3f/2c1ecff0a81ead0448e1215567ede7.png)
[high CPU consumption] software_ reporter_ tool.exe

What should testers know about login security?

这种动态规划你见过吗——状态机动态规划之股票问题(中)

The default isolation level of MySQL is RR. Why does Alibaba and other large manufacturers change to RC?
![[internal mental skill] - creation and destruction of function stack frame (C implementation)](/img/a9/81644ee9ffb74a5dc8ff1bc3977f49.png)
[internal mental skill] - creation and destruction of function stack frame (C implementation)

MySQL(5)

Activation functions sigmoid, tanh, relu in convolutional neural networks

【CVPR2022 oral】Balanced Multimodal Learning via On-the-fly Gradient Modulation

Read the paper -- a CNN RNN framework for clip yield prediction
随机推荐
DELL远程控制卡 使用ipmitools设置ipmi
Using RAC to realize the sending logic of verification code
Summary and review of puppeter
POJ 3417 network (lca+ differential on tree)
When initializing with pyqt5, super() and_ init _ () problems faced by the coordinated use of functions, as well as the corresponding learning and solutions
Data imbalance: comprehensive sampling of anti fraud model (data imbalance)
How to quickly locate bugs? How to write test cases?
Have you learned the common SQL interview questions on the short video platform?
【CPU占用高】software_reporter_tool.exe
Program life | how to switch to software testing? (software testing learning roadmap attached)
HashSet add
Microservice failure mode and building elastic system
Handling of web page image loading errors
HDU 1522 marriage is stable
Check box error
[internal mental skill] - creation and destruction of function stack frame (C implementation)
Improving the readability of UI layer test with puppeter
Anaconda common instructions
HDU 3078 network (lca+ sort)
Classes and objects [medium]