From: nick on 14 Apr 2010 20:53 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[i]; // do something with c... } } TIA for advice. -- Nick
From: 123Jim on 15 Apr 2010 04:07 "nick" <nick___(a)fastmail.fm> wrote in message news:8113edbc-079c-4bf9-88f1-df111b01f4ef(a)w17g2000yqj.googlegroups.com... > 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[i]; > // do something with c... > } > } > > TIA for advice. > > -- Nick don't use .split use .charAt see here: http://www.javascriptkit.com/javatutors/string4.shtml
From: nick on 15 Apr 2010 05:03 On Apr 15, 4:07 am, "123Jim" <jnkjnjn...(a)uhnuhnunuhnuy.invalid> wrote: > don't use .split > use .charAt Hmm, that would make sense now wouldn't it. Somehow I forgot that function existed... thanks for reminding me.
|
Pages: 1 Prev: navigator.appName Next: test code with firefox 3.5.8 or better |