当前位置:网站首页>JSON. Function of the stringify() optional parameter
JSON. Function of the stringify() optional parameter
2022-06-23 03:12:00 【It workers】
JSON.stringify Is a tool function we often use , The second optional parameter actually has some tricks , This article explains two common ways to use optional parameters .
Array
Use JSON.stringify() The second optional parameter of , Extract a specific field from an array by passing it in .
The implementation code is as follows :
var person = {"name":"Jim Cowart","location":{"city":{"name":"Chattanooga","population":167674}
,"state":{"name":"Tennessee","abbreviation":"TN","population":6403000}},"company":"appendTo"};
JSON.stringify(person, ["name", "company"], 4);
// ~> "{
// "name": "Jim Cowart",
// "company": "appendTo"
// }"function
In addition, this parameter can also be a function , Used to operate on data before it is returned . If you want to Set Stringing , It will be very convenient , for example :
const dude = {
name: "Pawel",
friends: new Set(["Dan", "Pedro", "Mr Gregory"])
};
const dudeStringified = JSON.stringify(dude, (key, value) =>
value instanceof Set ? [...value] : value
);
console.log(dudeStringified);
// ~> {"name":"Pawel","friends":["Dan","Pedro","Mr Gregory"]}边栏推荐
- HTTP cache
- Initial xxE
- Reading redis source code (VI) multi threading of redis 6.0
- Goframe framework (RK boot): rapid configuration of server CORS
- How does native JS get the child elements of the parent element that the current element belongs to
- 2022-01-25: serialize and deserialize n-ary tree. Serialization means that a
- Implementation process of the new electronic amplification function of easycvr video fusion cloud platform
- Evolution of cloud firewall products
- Quickly understand the development status of secondary nodes of industrial Internet identity analysis
- An implementation of universal interface caching Middleware
猜你喜欢
随机推荐
SAP mm initial transaction code MEK1 maintenance pb00 price
Cve-2021-4034 reappearance
MIT 6. S081/fall 2020 build risc-v and xv6 development and debugging environment
How to batch print serial and repeated barcode data
New uniapp+uniui background management uniuadmin
"Tianzhou II" successfully docked! Three minutes to understand the shocking black technology on "Tianzhou II"! Headlines
The metauniverse is just a cloak for future technological evolution
Chapter IV open source projects and deployment
Concept and function of ES6 symbol
Redis source code reading (I) general overview
Great WPF open source control library newbeecoder UI
Section 6: basic configuration I of spingboot
Wwdc21 - App store server API practice summary
Reading redis source code (VI) multi threading of redis 6.0
Quic implementation in rust --- Quinn
Implementation idea and solution of calling global monitoring for applet
February 4, 2022: combined total IV. Give you a number composed of different integers
Use Sakura FRP intranet penetration service to build your own website / game server
No error is reported when using the Gorm framework to create a table, but the data cannot be inserted successfully
[SaaS examination certification] apaas_ Tencent Qianfan magic pen