Split string once in javascript?

You’d want to use String.indexOf('|') to get the index of the first occurrence of ‘|’.

var i = s.indexOf('|');
var splits = [s.slice(0,i), s.slice(i+1)];

Leave a Comment