当前位置:网站首页>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"]}边栏推荐
- Exploration on the framework of stream batch integration technology and its practice in kangaroo cloud number stack
- Installing serverstatus probe using pagoda
- Learning records - things inherited by subclass parent of C #
- Add other view components to the audio and video components of the applet
- Scanning technology (getting started with web security 06)
- Troubleshooting and solution of error 400 in easygbs video platform
- February 2, 2022: the closest binary search tree value II. Given a non empty two
- Implementation idea and solution of calling global monitoring for applet
- Learning record -- memo on constructors and attributes in C
- The cloud disk has been offline from the internal machine, but the console uninstall failed
猜你喜欢
随机推荐
Micro build low code to realize user login and registration
Section 6: basic configuration I of spingboot
Implementing StdevP function of Excel with PHP
[data preparation and Feature Engineering] data cleaning
2022-01-27: heater. Winter has come. Your task is to design a
The logical operators |, & &!
How to use fortress on mobile devices
How to make special labels for books
How to gracefully solve the problem of platform font adaptation
2022-01-22: Li Kou 411, the abbreviation of the shortest exclusive word. Give a string number
RI Geng series: potential memory leak caused by abuse of mutable in Google Pb structure
Installing serverstatus probe using pagoda
Detailed explanation of label smoothing and implementation of pytorch tenorflow
MIT 6. S081/fall 2020 build risc-v and xv6 development and debugging environment
Cve-2021-4034 reappearance
CFs of cifs/smb protocol is mounted on win10/2019. Error 1272 is reported. The security policy prevents unauthenticated guest access
Pond sampling
Enterprise official website applet building tutorial - solution
Win11 client remote ECS black screen
How to make keyword targeted layout based on search sources?