770 snippets from 1549 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(136)
JavaScript
(123)
Java
(66)
VBSCRIPT
(58)
String
(44)
CSS
(31)
CSharp
(28)
File
(28)
HTML
(27)
C
(24)
mysql
(24)
VB.NET
(24)
python
(24)
CPlusPlus
(23)
groovy
(23)
New Snippets
Very lightweight ...
AutoComplete plug...
AutoComplete plug...
Connection Java -...
View PostgreSql
Store Procedure
Pygame - Simple p...
Python - Anagram ...
Python - Anagram ...
Converter to bina...
Venture Capital Jobs
New Members
me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Hackdemian
impomatic
Top Members
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Home
/
Snippets
/
Javascript Array to String
/
Comments
Javascript Array to String
Snippet Menu
Revisions
Comments
Related Snippets
Add to Favorites
Email Snippet
Download Snippet
Print Snippet
Blog Snippet
snippet
|
revisions
|
comments
|
related
|
Add to Favorites
|
email
download
|
print
|
blog it
New Comment
Escape
Sat. Oct. 28th, 2006 4:23 PM
SCoon
You have to escape string values to provide valid string literals.
Use following to reproduce defect in your function.
arr =
new
Array
(
)
;
arr
[
1
]
=
'Foo " bar'
;
alert
(
arrayToString
(
arr
)
)
;
// new Array("", "Foo " bar")
Reply
Doesn't seem necessary
Tue. Oct. 10th, 2006 8:34 PM
drench
Since setTimeout (and setInterval) will take a function as an argument, you don't need to stringify. It's less bug-prone too (what if one of your array elements had a comma in it, or was an object not easily stringified?) See snippet below.
setTimeout
(
function
(
)
{
my_function
(
my_arg_array
)
}
,
1000
)
Reply
Why?
Mon. Oct. 9th, 2006 1:20 AM
phatcat
"["+myArray.toString()+"]"
It's already done for you. And if you find yourself going through the trouble in the first place you're already doing something wrong.
The only time I've ever done anything close is for XMLHttpResponse Server -> Client ... and even that's a hack IMO.
Yeesh.
Reply
New Comment
Use following to reproduce defect in your function.
arr[1] = 'Foo " bar';
alert(arrayToString(arr)); // new Array("", "Foo " bar")
setTimeout(function () { my_function(my_arg_array) }, 1000)
It's already done for you. And if you find yourself going through the trouble in the first place you're already doing something wrong.
The only time I've ever done anything close is for XMLHttpResponse Server -> Client ... and even that's a hack IMO.
Yeesh.