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)];
More Related Contents:
- Javascript Array – Split string at numbers [closed]
- Split array into chunks
- How do I split a string with multiple separators in JavaScript?
- Is there a built in way to convert a comma-separated string to an array?
- How can I parse a CSV string with JavaScript, which contains comma in data?
- Split large string in n-size chunks in JavaScript
- How can I convert a comma-separated string to an array?
- How can I split a string into segments of n characters?
- How to use split?
- JS string.split() without removing the delimiters [duplicate]
- javascript regex split produces too many items
- Javascript split string on space or on quotes to array
- How to split a string at the first `/` (slash) and surround part of it in a “?
- Javascript split regex question
- JavaScript split String with white space
- Split a string based on multiple delimiters
- Split JavaScript array in chunks using Lodash
- javascript split string by space, but ignore space in quotes (notice not to split by the colon too)
- String split returns an array with more elements than expected (empty elements)
- Split by Caps in Javascript
- Javascript: Splitting a string by comma but ignoring commas in quotes
- split an array into two based on a index in javascript
- Unicode string with diacritics split by chars
- How do you split a javascript string by spaces and punctuation?
- How to count the number of lines of a string in javascript
- Sending Variable From Php To Js [duplicate]
- How to clear the contents of an iFrame from another iFrame
- Simulate Keypress With jQuery
- Showing C# tags in Jekyll Github pages using Highlight.js
- How to make a document.getElementById value into an integer variable, not a string?