JavaScript converts objects into strings, generally using JSON.stringify().
1. The JSON.stringify() method converts a JavaScript value (object or array) into a JSON string. If replacer is specified as a function, the value can be replaced, or if replacer is specified is an array, optionally including only specified attributes.
2. Running instance diagram:
Extended information:
Syntax: JSON.stringify(value[, replacer [, space]])
Parameters:
1. Value is the value to be serialized into a JSON string.
2. replacer (optional), if the parameter is a function, during the serialization process, each attribute of the serialized value will be converted and processed by the function; if the parameter is an array, then only the attribute names contained in this array will be serialized into the final JSON string; if this parameter is null or not provided, all attributes of the object will be serialized;
3. space (optional), specifies the blank string used for indentation, used to beautify the output (pretty-print); if the parameter is a number, it represents the number of spaces; the upper limit is 10. If the value is less than 1, it means there are no spaces; if the parameter is a string (the first ten letters of the string), the string will be treated as spaces; if the parameter is not provided (or is null) there will be no spaces.
Return value: a JSON string representing the given value.
MDN web docs—JSON.stringify()