Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

string charat javascript

let str = new String("This is string"); 
console.log("str.charAt(0) is:" + str.charAt(0)); 
console.log("str.charAt(1) is:" + str.charAt(1)); 
console.log("str.charAt(2) is:" + str.charAt(2)); 
console.log("str.charAt(3) is:" + str.charAt(3)); 
console.log("str.charAt(4) is:" + str.charAt(4)); 
console.log("str.charAt(5) is:" + str.charAt(5));

output:

str.charAt(0) is:T 
str.charAt(1) is:h 
str.charAt(2) is:i 
str.charAt(3) is:s 
str.charAt(4) is:
str.charAt(5) is:i
Comment

charat javascript

// The charAt() method returns the character at a specified index (position) in a string.
// The index of the first character is 0, the second 1, ...
// The index of the last character is string length - 1

let text = "HELLO WORLD";
let letter = text.charAt(0); // H

let text = "HELLO WORLD";
let letter = text.charAt(1); // E

let text = "HELLO WORLD";
let letter = text.charAt(text.length-1); // D
Comment

The ".charAt()" JavaScript string method

// You use this method to retrieve the character at a specified position in a string. Using this method,
// we can retrieve the first letter in a word:

const word = "freecodecamp"

const firstLetter = word.charAt(0)
// f
Comment

charAt javascript

myString = "Hello World!";

console.log(myString.charAt(0)); // outputs "H"
console.log(myString.charAt(5)); // outputs " "
console.log(myString.charAt(8)); // outputs "r"
/* If the specified index is bigger or equal to the length of the string
   the output will be "". */
console.log(myString.charAt(23)); // outputs ""
Comment

PREVIOUS NEXT
Code Example
Javascript :: solidity payable 
Javascript :: Import A Module In ExpressJS 
Javascript :: set tiemzone datetime object 
Javascript :: JS how to access a class propert 
Javascript :: javascript destructuring 
Javascript :: print console.log 
Javascript :: react native intro slider 
Javascript :: particle js 
Javascript :: react native stepper 
Javascript :: fibonacci series javascript using recursion explanation 
Javascript :: ternary javascript 
Javascript :: javascript unicode 
Javascript :: get jsonp with fetch 
Javascript :: resize window javascript 
Javascript :: break loop if condition is met 
Javascript :: how to add comment in javascript 
Javascript :: javascript start 
Javascript :: base64 
Javascript :: join javascript array 
Javascript :: how to make pdf of web page 
Javascript :: using mongoose with node js 
Javascript :: how to make and add to an array in javascript 
Javascript :: js react 
Javascript :: AJAX GET Requests 
Javascript :: js function definition 
Javascript :: code splitting react 
Javascript :: JavaScript finally() method 
Javascript :: map function 
Javascript :: usereducer in react 
Javascript :: jquery dynamic row number not working properly 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =