Reputation: 757
I'm having a strange problem trying to split a string, I split it once and save it as a variable, but then I try to split the value that I've just created and I can't, it throws an error saying: Cannot call method 'split' of undefined
justName = fullLine.split('(', 1)[0];
dateOne = fullLine.split('(', 2)[1];
dateTwo = dateOne.split(')', 1);
console.log(dateTwo);
If I log out justName then there is no problem.
An example of fullLine would be :
In the Heat of the Night (1967)
Upvotes: 2
Views: 2024
Reputation: 3353
var str="In the Heat of the Night (1967)";
dateOne = str.split('(', 2)[1];
dateTwo = dateOne.split(')', 1);
console.log(dateTwo);
It is working fine
Upvotes: 1
Reputation: 7562
I can see it working. Check this jsFiddle here.
<div id="a"></div>
<input type="button" onclick="abc()" value="Split" />
function abc(){
var fullLine="hello(world)Qwerty";
justName = fullLine.split('(', 1)[0];
dateOne = fullLine.split('(', 2)[1];
dateTwo = dateOne.split(')', 1);
alert(dateTwo);
}
Upvotes: 1