Languages
[Edit]
EN

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

1 points
Created by:
Paris-Bateman
434

In this article, we would like to show you how to split string by hyphen sign in JavaScript.

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

Practical example

// ONLINE-RUNNER:browser;

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

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

console.log(element1); // split
console.log(element2); // this
console.log(element3); // text

Output:

split
this
text

Alternative titles

  1. JavaScript - how to split string by hyphen sign (minus sign - ascii 45 code)
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - split string by hyphen 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.

❤️💻 🙂

Join