Languages
[Edit]
EN

JavaScript - get substring of string

0 points
Created by:
Admin Dirask Community
1450

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 = "dirask is cool";
let substring = text.substring(0, 7);   // start from index 0 up to 7
console.log(substring);                 // dirask

 

Practical example

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

// ONLINE-RUNNER:browser;

let text = "dirask is cool"

let substring1 = text.substring(0, 7)     // dirask    (start from index 0 to 7)
let substring2 = text.substring(7, 9)     // is
let substring3 = text.substring(7)        // is cool   (from index 7 to the end of the string)

console.log(substring1)  // dirask
console.log(substring2)  // is
console.log(substring3)  // is cool

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