![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I understand that string.split() should produce an array from a string. However when I use the following script the type of the result is indeed an object but the array elements are undefined. Why? var strTest = '1,2,3,4'; var aryTest = strTest.split(); alert(typeof aryTest + " " + aryTest[2]); |
#3
| |||
| |||
|
|
var strTest = '1,2,3,4'; var aryTest = strTest.split(); alert(typeof aryTest + " *" + aryTest[2]); |
#4
| |||
| |||
|
|
var strTest = '1,2,3,4'; var aryTest = strTest.split(); alert(typeof aryTest + " " + aryTest[2]); Hey, you didn't tell your JavaScript VM where to split! Try this: var strTest = '1,2,3,4'; var aryTest = strTest.split(','); alert(typeof aryTest + " " + aryTest[2]); Looks better? Yes it does. |
#5
| |||
| |||
|
|
Steve meinte: However according to the material I have read, including the Rhino, the comma is the default. But I should have thought of that anyway. Read again. Mozilla doesn't state a "default separator". Instead "If separator is omitted, the array returned contains one element consisting of the entire string." [1] I suppose other ECMAScript derivates behave equally. |
![]() |
| Thread Tools | |
| Display Modes | |
| |