I tried use javascript spilt to get part of the word : new from What#a_new%20day
I tried code like this:
<script>
var word="What#a_new%20day";
var newword = word.split("%20", 1).split("_", 2);
alert(newword);
</script>
But caused:
Uncaught TypeError: Object What#a_new has no method 'split'
Maybe there have more wiser way to get the word which I need. So can anyone help me? Thanks.
splitreturns an array, so the secondsplitis trying to operate on the array returned by the first, rather than a string, which causes a TypeError. You’ll also want to add the correct index after the second call tosplit, ornewwordwill also be an array, not the String you’re expecting. Change it to:This splits
word, then splits the string at index 0 of the resulting array, and assigns the value of the string at index 1 of the new array tonewword.