Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  25] [ 7]  / answers: 1 / hits: 55159  / 8 Years ago, mon, september 19, 2016, 12:00:00

Let's say I have a paragraph that says 55+5. I want to have JavaScript return everything before the plus. Is this possible using substrings?


More From » javascript

 Answers
11

Yes. Try the String.split method: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/split


split() returns an array of strings, split by the character you pass to it (in your case, the plus). Just use the first element of the array; it will have everything before the plus:


const string = "foo-bar-baz"
const splittedString = string.split('-')
//splittedString is a 3 element array with the elements 'foo', 'bar', and 'baz'

[#60672] Friday, September 16, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taylert

Total Points: 627
Total Questions: 91
Total Answers: 108

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
taylert questions
;