support for <string>.split("")

N

nick

Quick question...

It's my understanding that accessing a string as an array of
characters is a non-standard feature, not supported everywhere. I have
some code where I want to access a string as an array of characters.

When I call .split("") on a string (the argument is an empty string),
an array-like object is returned with each element being one character
of the original string. How widely supported is this behavior? Should
the example code below work in the major desktop and mobile browsers?

example code:

function something (str) {
if (!' '[0]) str = str.split('');
for (var i=0; i<str.length; i++) {
var c = str;
// do something with c...
}
}

TIA for advice.

-- Nick
 
1

123Jim

nick said:
Quick question...

It's my understanding that accessing a string as an array of
characters is a non-standard feature, not supported everywhere. I have
some code where I want to access a string as an array of characters.

When I call .split("") on a string (the argument is an empty string),
an array-like object is returned with each element being one character
of the original string. How widely supported is this behavior? Should
the example code below work in the major desktop and mobile browsers?

example code:

function something (str) {
if (!' '[0]) str = str.split('');
for (var i=0; i<str.length; i++) {
var c = str;
// do something with c...
}
}

TIA for advice.

-- Nick


don't use .split
use .charAt
see here:
http://www.javascriptkit.com/javatutors/string4.shtml
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top