Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to Get the First N Characters of a String in JavaScript

// substring() Method

const str = 'Coding Beauty';

const first3 = str.substring(0, 3);
console.log(first3); // Cod

const first5 = str.substring(0, 5);
console.log(first5); // Codin

const first11 = str.substring(0, 11);
console.log(first11); // Coding Beau
Source by javascript.plainenglish.io #
 
PREVIOUS NEXT
Tagged: #How #Get #First #N #Characters #String #JavaScript
ADD COMMENT
Topic
Name
2+7 =