Home>Article>Web Front-end> How to convert javascript object into string
In javascript, you can use the "JSON.stringify()" method to convert an object into a string, and its syntax is such as "JSON.stringify(value[, replacer [, space]])".
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript converts objects into strings, generally using JSON.stringify().
The JSON.stringify() method converts a JavaScript value (object or array) into a JSON string. If replacer is specified to be a function, the value can be replaced, or if replacer is specified to be an array. , optionally including only the specified attributes.
Running example 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 property names contained in this array will be serialized into the final JSON string; if this parameter is null or not provided, all properties 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.
【Recommended learning:javascript advanced tutorial】
The above is the detailed content of How to convert javascript object into string. For more information, please follow other related articles on the PHP Chinese website!