A simple JSON stringify function which requires Array.prototype.map method.
The following users provided lots of ideas and improvements of the code.
@Kambfhase, @hartrock, @atk, @haochi, @jed
Actually, I just provided a deficient version at first. The other versions were created by these users(especially @atk). You may see the discussion below.
Result
f({}) -> Object { }
is wrong for a valid input (whichnull
is not); it even does not return a string, which is what this method is supposed to do.OK, this is not so hard as in other languages, but it is not parseable by
JSON.parse()
.