Third argument from JSON.stringify is "space".

Argument "space" was spelt "spacer" or "spaces" in the article.
This commit is contained in:
Pascal BOURUT 2019-08-20 15:21:31 -07:00 committed by GitHub
parent a38ab40724
commit 2ad0ff194b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -286,13 +286,13 @@ The first call is special. It is made using a special "wrapper object": `{"": me
The idea is to provide as much power for `replacer` as possible: it has a chance to analyze and replace/skip even the whole object if necessary. The idea is to provide as much power for `replacer` as possible: it has a chance to analyze and replace/skip even the whole object if necessary.
## Formatting: spacer ## Formatting: space
The third argument of `JSON.stringify(value, replacer, spaces)` is the number of spaces to use for pretty formatting. The third argument of `JSON.stringify(value, replacer, space)` is the number of spaces to use for pretty formatting.
Previously, all stringified objects had no indents and extra spaces. That's fine if we want to send an object over a network. The `spacer` argument is used exclusively for a nice output. Previously, all stringified objects had no indents and extra spaces. That's fine if we want to send an object over a network. The `space` argument is used exclusively for a nice output.
Here `spacer = 2` tells JavaScript to show nested objects on multiple lines, with indentation of 2 spaces inside an object: Here `space = 2` tells JavaScript to show nested objects on multiple lines, with indentation of 2 spaces inside an object:
```js run ```js run
let user = { let user = {
@ -328,7 +328,7 @@ alert(JSON.stringify(user, null, 2));
*/ */
``` ```
The `spaces` parameter is used solely for logging and nice-output purposes. The `space` parameter is used solely for logging and nice-output purposes.
## Custom "toJSON" ## Custom "toJSON"