Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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

// slice() Method

const str = 'Coding Beauty';

const first2 = str.slice(0, 2);
console.log(first2); // Co

const first6 = str.slice(0, 6);
console.log(first6); // Coding

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