JavaScript - split string by hyphen sign (minus sign - ascii 45 code)

1 points
Created by:

In JavaScript string has split method. 

String split() function takes as parameter character by which the string will be splitted into array of substrings. As the result of String split() we get array. To access element we just get element by it's index.

Run below example to see how it works in practice.

// ONLINE-RUNNER:browser;

var text = 'split-this-text';
var split = text.split('-');

var element1 = split[0]; // split
var element2 = split[1]; // this
var element3 = split[2]; // text

console.log( element1 );
console.log( element2 );
console.log( element3 );


JavaScript - String (popular problems)

JavaScript - split string by hyphen sign (minus sign)
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂