Javascript - Extracting String Characters

Introduction

There are two methods for extracting string characters:

  • charAt(position)
  • charCodeAt(position)

charAt() Method

The charAt() method returns the character at a specified position in a string:

Demo

var str = "HELLO WORLD";
console.log(str.charAt(0));

Result

charCodeAt() Method

The charCodeAt() method returns the unicode of the character at a specified index in a string:

Demo

var str = "HELLO WORLD";
console.log(str.charCodeAt(0));

Result

Related Topic