DekGenius.com
JAVASCRIPT
how to get the first character of a string in javascript
let str = 'John Wick'
let firstChar = str.charAt(0)
console.log(firstChar); // "J"
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
javascript get first 2 char
String.substring(0, 2);
//Return the first two characters of the string
//First parameter is the starting index, 0 corresponding to the first character
//Second parameter is the number of character to return
javascript get first 3 characters of string
const str = 'Walk the dog';
const first3 = str.slice(0, 3);
js get first 3 characters of string
const string = "0123456789";
console.log(string.slice(0, 2)); // "01"
console.log(string.slice(0, 8)); // "01234567"
console.log(string.slice(3, 7)); // "3456"
first x characters of string javascript
let string = "abcdefghi"
console.log(string.slice(0, 3))
// abc
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
javascript get first 3 characters of string
get first 10 characters of string javascript
© 2022 Copyright:
DekGenius.com