“String Charat JavaScript” Réponses codées

javascript obtient le premier caractère de la chaîne

var str="Hello Folks!"
var firstStringChar = str.charAt(0); //H
Grepper

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
Chetan Nada

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
Creepy Gábor

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 ""
The Code Slayer

Réponses similaires à “String Charat JavaScript”

Questions similaires à “String Charat JavaScript”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code