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 :: react navbar responsive 
Javascript :: enzyme airnb 
Javascript :: hasownproperty.call 
Javascript :: angular auth guard 
Javascript :: sample promise.all javascript 
Javascript :: java script alerts 
Javascript :: array of 
Javascript :: how to make popup modal in jquery with example 
Javascript :: Promise.prototype.finally 
Javascript :: check the type of a variable in js 
Javascript :: find in js 
Javascript :: what does onchange do in react 
Javascript :: ArduinoJson.h 
Javascript :: fetch in vue 3 
Javascript :: json html 
Javascript :: default value of functin atribute 
Javascript :: javascript array remove last 
Javascript :: resize window javascript 
Javascript :: slice in js 
Javascript :: javascript variable scope 
Javascript :: Set an onclick function with a parameter for an element 
Javascript :: js exports 
Javascript :: componentDidmount event on fonctional component 
Javascript :: how to add multiple objects into array in javascript 
Javascript :: convert json data into html table 
Javascript :: what is cross browser testing 
Javascript :: how to add class in jquery 
Javascript :: add 2 class names react 
Javascript :: js object 
Javascript :: what is heap in javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =