Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Strings 3/5 | Data Types and Variables
Introduction to JavaScript (staging)

bookStrings 3/5

Accessing Character:

We can also access different characters from a string variable, and for that, we use the square brackets []. The syntaxes for accessing characters are str.charAt(pos) and variableName(pos) where pos is the position or index of the character that we want to access and variableName is the variable to be sliced. Let’s look at an example.

123
let str = 'JavaScript'; console.log(str[0] ); console.log( str.charAt(4));
copy
Tâche

Swipe to start coding

A string value, England, is stored in a variable named country. The task is to display the letter a of the variable England.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 21
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Can you explain the difference between using square brackets and the charAt() method?

What will happen if I try to access an index that is out of range?

Can you show more examples of accessing characters in a string?

close

bookStrings 3/5

Glissez pour afficher le menu

Accessing Character:

We can also access different characters from a string variable, and for that, we use the square brackets []. The syntaxes for accessing characters are str.charAt(pos) and variableName(pos) where pos is the position or index of the character that we want to access and variableName is the variable to be sliced. Let’s look at an example.

123
let str = 'JavaScript'; console.log(str[0] ); console.log( str.charAt(4));
copy
Tâche

Swipe to start coding

A string value, England, is stored in a variable named country. The task is to display the letter a of the variable England.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 21
single

single

some-alt