Languages
[Edit]
EN

JavaScript - get substring from end

0 points
Created by:
Blythe-F
290

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

Quick solution:

text.substring(text.length - substringLength);

 

Practical example

In this example, we specify the length of the substring we want to get, then we use substring() method to get the last substringLength characters of the text string.

// ONLINE-RUNNER:browser;

const text = 'ABC DEF';
const substringLength = 3;

const result = text.substring(text.length - substringLength);

console.log(result); // DEF

References

  1. String.prototype.substring() - JavaScript | MDN 
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