Search
 
SCRIPT & CODE EXAMPLE
 

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" 
Comment

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
Comment

javascript get first 3 characters of string

const str = 'Walk the dog';

const first3 = str.slice(0, 3);
Comment

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"
Comment

first x characters of string javascript

let string = "abcdefghi"
console.log(string.slice(0, 3))
// abc
Comment

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
Comment

javascript get first 3 characters of string

String.substring(0, 3);
Comment

get first 10 characters of string javascript

String.substring(0, 10);
Comment

PREVIOUS NEXT
Code Example
Javascript :: chart js y axis integer 
Javascript :: arrow function forms in javascript 
Javascript :: how to concurrently run angular and node 
Javascript :: js encryption two way 
Javascript :: Nazmul 
Javascript :: mongoose connect url 
Javascript :: type numeric value only in textbox javascript 
Javascript :: cy url contains 
Javascript :: javascript check if not null 
Javascript :: javascript object to json 
Javascript :: time difference in minutes in JS 
Javascript :: calculate string value in javascript, not using eval 
Javascript :: react-native curved view 
Javascript :: nodejs how cpu handle worker_threads 
Javascript :: get image url in react input file or preview form image 
Javascript :: prompt node 
Javascript :: showing an image in react js 
Javascript :: angular download blob pdf 
Javascript :: javascript object total 
Javascript :: option selected jquery 
Javascript :: javascript redirect to a page 
Javascript :: get first two letter of an array javascript 
Javascript :: react style ternary operator 
Javascript :: reactjs link props 
Javascript :: datepicker get selected date 
Javascript :: js check which number is larger 
Javascript :: onclick event in angular 
Javascript :: ng build staging 
Javascript :: javascript add element next to another 
Javascript :: javascript password validation regex test 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =