A better javascript to string function?
Posted
by
Jeff
on Stack Overflow
See other posts from Stack Overflow
or by Jeff
Published on 2011-01-29T23:23:19Z
Indexed on
2011/01/29
23:25 UTC
Read the original article
Hit count: 139
JavaScript
|string
Before I go and create this myself, I thought I'd see if anyone knows a library that does this.
I'm looking for a function that will take something in Javascript, be it an array, an associative array, a number, or even a string, and convert it to something that looks like it. For example:
toString([1,2,3]) === '[1, 2, 3]'
toString([[1,2], [2,4], [3,6]]) === '[[1,2], [2,4], [3,6]]'
toString(23) === '23'
toString('hello world') === 'hello world'
toString({'one': 1, 'two': 2, 'three': 3}) === "{'one': 1, 'two': 2, 'three': 3}"
© Stack Overflow or respective owner