|
-
Nov 12th, 2006, 03:53 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Javascript array.join ignoring specified delimiter
Hi,
Can anyone see why the below join isn't working? It insists on joining the string with a comma ",". It's not the "~" as I've tried changing the delimiter to dot "." and "|" with no effect and it's not the splice as I've commented it out and that didn't make any difference either
Code:
<html>
<body>
<script type="text/javascript">
var item=1;
var val="jani~hege~stale";
val=val.split("~");
if(val.length>=item){
val.splice(item,1);
val.join("~");
}
alert(val);
</script>
</body>
</html>
Any help will be greatly appreciated
Cheers Al
Last edited by aconybeare; Nov 12th, 2006 at 04:07 AM.
Reason: improve title
-
Nov 12th, 2006, 05:13 AM
#2
Re: Javascript array.join ignoring specified delimiter
What browser does it fail in? A command like this:
""jani~hege~stale".split("~").join("~")"
works fine in my Firefox 1.5. It also works in Opera. I was too lazy to test in Konqueror, which didn't like JavaScript being entered directly in the address bar.
Edit: OK, I know what your error is. Like split(), join() does not modify the object it is called on but instead returns the string it creates. You don't assign this string to anything. Thus what your alert displays is just the default stringification of the array, which uses commas.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 12th, 2006, 06:33 AM
#3
Thread Starter
Fanatic Member
Re: Javascript array.join ignoring specified delimiter
CornedBee,
Thanks for your reply, using ie7.
Haven't tested this, but I take it what you're saying is that I need to assign the join to a variable.
Cheers Al
Last edited by aconybeare; Nov 13th, 2006 at 03:31 AM.
-
Nov 12th, 2006, 06:45 AM
#4
Re: [RESOLVED] Javascript array.join ignoring specified delimiter
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|