I know the split routine of JavaScript. I've a string in this pattern Employee - John Smith - Director.
I want to split it on the base of first hyphen using JavaScript and it'll seem like:
Source: Employee
Sub: John Smith - Director
I know the split routine of JavaScript. I've a string in this pattern Employee - John Smith - Director.
I want to split it on the base of first hyphen using JavaScript and it'll seem like:
Source: Employee
Sub: John Smith - Director
I would use a regular expression:
b = "Employee - John Smith - Director"
c = b.split(/\s-\s(.*)/g)
c
["Employee", "John Smith - Director", ""]
So you have in c[0] the first word and in c[1] the rest.
var str = "Employee - John Smith - Director "
str.split("-",1)
Then to split other use this link: How can I split a long string in two at the nth space?
you can do like
var str = "Employee - John Smith - Director "
var s=str.split("-");
s.shift() ;
s.join("-");
console.log(s);