JS: charAt() Method

JavaScript programming treat the strings as array and each character of the string has an index.

Advertisements

Suppose we want to know the character at index 1. The JavaScript string class has method called <span style="color:#a30f00" class="tadv-color">charAt()</span> that returns the character at a index from the string.

Advertisements

The <span style="color:#a33100" class="tadv-color">charAt(1) </span>will return a character from string at index location 1.

<!DOCTYPE html>
<html>
<head>
   <title>JS: charAt() Method</title>
   <meta charset="utf-8">
</head>
<body>
<script>
  var country = "HOLLAND";
  console.log(country.charAt(4));
//output = 'A'
</script>
</body>
</html>

In the above script, we want to know which character is located at index location 4. The <span style="color:#a30500" class="tadv-color">charAt()</span> method will return ‘A’ from the string.

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.