Forum Moderators: open
Example:
str = "camelCasedWord";
document.write(str.split(/[A-Z]/)); //writes camel,ased,ord
str = "camelCasedWord";
document.write(str.split(/([A-Z])/)); //writes camel,C,ased,W,ord
I want it to return camel,Cased,Word
var words = [];
var j=0;
for (var i=0;i<str.length;i++){
var thisletter = str.substring(i,i);
if(thisletter == thisletter.toUpperCase()){ // it's an upper case letter
j++;
}
words[j] = words[j] + thisletter;
}
this is a simple, untested snippet... side effect would be if the word starts with a capital letter, array[0] would be blank and the first word would begin at array[1]