Freewsad
HomeBlogsBooks Categories
Log inRegister
Menu
Freewsad - The best educational website

HomePrivacy PolicyAbout UsContact UsCategories

Copyright© 2021 - 2025 All rights reserved.

How to Get Character of Specific Position using JavaScript ?

How to Get Character of Specific Position using JavaScript ?

At 6/7/2023

In this article, we will see how to get the character of a specific position using JavaScript. There are three methods to get the character at a specific position using JavaScript. These are:

  • Using String charAt() Method
  • Using String substr() Method
  • Using Square Bracket Notation

Using String charAt() Method: The charAt() method is used to get the character at a specific position in a string. This method takes the index as an argument and returns the character of the given index in the string.

Example:

Javascript

let str = "Welcome to Freesad";
let index = 11;
let ctr = str.charAt(index);
console.log("Character at " + index + "th position is: " + ctr);

Output:

Character at 11th position is: F

Using String substr() Method: The substr() method can also be used to get the character at a specific position in a string. This method returns the specified number of characters from a string, starting from the given index.

Example:

Javascript

let str = "Welcome to Freesad";
let index = 11;
let ctr = str.substr(index, 1);
console.log("Character at " + index + "th position is: " + ctr);

Output:

Character at 11th position is: F

Using Square Bracket Notation: The square bracket can also be used to get the character at a specific position in a string.

Example:

Javascript

let str = "Welcome to Freesad";
let index = 11;
let ctr = str[index];
console.log("Character at " + index + "th position is: " + ctr);

Output:

Character at 11th position is: F

Copyrights

We respect the property rights of others and are always careful not to infringe on their rights, so authors and publishing houses have the right to demand that an article or book download link be removed from the site. If you find an article or book of yours and do not agree to the posting of a download link, or you have a suggestion or complaint, write to us through the Contact Us, or by email at: support@freewsad.com.

More About us