Languages
[Edit]
EN

JavaScript - get substring of string

0 points
Created by:
maryam
251

In this article, we would like to show you how to get a substring of the string in JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

let text = 'ABCD';
let substring = text.substring(1, 3);   // start from index 1 up to 3

console.log(substring);                 // BC

 

Practical example

In this example, we present different cases of how to get a substring from the text.

// ONLINE-RUNNER:browser;

let text = 'ABCDE';

let substring1 = text.substring(0, 3)     // ABC
let substring2 = text.substring(3, 5)     // DE
let substring3 = text.substring(3)        // DE   (from index 3 to the end of the string)

console.log(substring1)  // ABC
console.log(substring2)  // DE
console.log(substring3)  // DE

JavaScript - String (popular problems)

JavaScript - get substring of string
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