How to use String at() Method In Javascript
The String.at() method is a modern way to get the character at a specific position in a string. This method takes an index as an argument and returns the character at the given index. One advantage of using String.at() is that it supports negative indices, which means you can easily get characters starting from the end of the string.
Example: In this example, we are finding the element at index 11 using the String.at() Method
let str = "Welcome to w3wiki";
let index = 11;
let character = str.at(index);
console.log("Character at " + index + "th position is: " + character);
Output
Character at 11th position is: G
How to Get Character of Specific Position using JavaScript ?
Get the Character of a Specific Position Using JavaScript We have different approaches, In this article we are going to learn how to Get the Character of a Specific Position using JavaScript
Below are the methods to get the character at a specific position using JavaScript:
Table of Content
- Method 1: Using String charAt() Method
- Method 2: Using String substr() Method
- Method 3: Using Square Bracket Notation
- Method 4: Using slice() Method
- Method 5: Using String at() Method