Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
111
rated 0 times [  118] [ 7]  / answers: 1 / hits: 47585  / 14 Years ago, wed, march 2, 2011, 12:00:00

First I set a variable, and set it to empty:



var str = ;


Then I split it through &:



var strs = str.split('&');


In the end, I show strs's length:



alert( strs.length);


It alert 1.



But I assign nothing to the 'str' variable. Why does it still have a length, should't it be zero?


More From » split

 Answers
-7

From the MDC doc center:




Note: When the string is empty, split returns an array containing one empty string, rather than an empty array.




Read the full docs here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split



In other words, this is by design, and not an error :)


[#93508] Monday, February 28, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arturo

Total Points: 331
Total Questions: 99
Total Answers: 92

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
arturo questions
;