I'm using jQuery.
serialize seems not fit for this job.
You can call join()
on your array to combine the elements into a string. And split()
can be used to split a string into an array, with optional seperator and limit parameters.
It's not clear what you're looking for, if you just want the array represented as a string then you can call toString
, which most types in javascript have defined:
>>> [1,2,3].toString()
"1,2,3"
The only serialisation on ‘arbitrary objects’ is toString
as described by thenduks. This is a convenience serialisation for display purposes only (and even then very often generates useless string representations like [object Object]
).
Can this process be reversed?
Not reliably, no.
If the datatypes you need to serialise are just the JS builtins like Array, String, Number and unprototyped Object being used as a transparent mapping, you can use JSON. Call JSON.stringify(obj)
to serialise, JSON.parse(str)
to re-parse. Use json2 or some other library with JSON features to support old browsers that don't have native JSON.
But ‘arbitrary objects’? No, can't be done (not in most other languages either).