javascript - Split string by word -


i have multiple strings assigned variables has common word. how can split these strings in 2 parts common word?

var str= "12344a56789"; 

instead of having write substring multiple times, there way split string 4a , following results?

var first = "1234"; var second = "56789"; 

note: each string lengths different.

you can using :

var splitted = str.split('4a'); //this output ["12344", "56789"] var first = splitted[0]; //"12344" var second = splitted[1]; //"56789" 

see. https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/string/split


Comments