Can anyone explain why this code behaves this way?
function reverseString(str) {
var chars = str.split();
chars.reverse();
chars.join();
return chars;
}
reverseString("dog");
Output is:
[“dog”]
Can anyone explain why this code behaves this way?
function reverseString(str) {
var chars = str.split();
chars.reverse();
chars.join();
return chars;
}
reverseString("dog");
Output is:
[“dog”]
Ah, so .split() on a string creates a single element array? I thought it split the string into an array of characters.
God I miss real Java. Never thought I would say that…
Thanks Randell