1.

Boolean Typed Array exist in JavaScript?

Answer»

To display the unicode of the character at a specified index in a string with JavaScript, use the charCodeAt() method.

Let us now see the syntax:

string.charCodeAt(index)

Here, “index” is the index of the character we are willing to return.

The method returns the Unicode of the character. However, "NaN" is returned if no character is found at the index we added as the parameter. 

The following is an example:

<!DOCTYPE HTML> <html> <body> <script>    var myStr = "Chatting!";    var res = myStr.charCodeAt(0);    document.write( "Unicode = " + res.toString() ); </script> </body> </html>

The output displays the returned Unicode of the 1st character, since we added parameter as 0: 

Unicode = 67

The following is another example wherein we will find out the Unicode for character at index 2: 

<!DOCTYPE html> <html> <body> <script>    var myStr = "HIT Wicket!!";    var res = myStr.charCodeAt(2);    document.write( "Unicode = " + res.toString() ); </script> </body> </html>

The output displays the returned Unicode of the 3rd character, since we added parameter index as 2:

 Unicode = 116

Let us see a CONDITION in which we are finding the character at a position where there is no character:

<!DOCTYPE html> <html> <body> <script>    var myStr = "abc";    // 5th character does not EXIST    var res = myStr.charCodeAt(5);    // NaN is returned    document.write( "Unicode = " + res.toString() ); </script> </body> </html>

Above, “NaN” is returned since there is no character at position 5th: 

Unicode = NaN


Discussion

No Comment Found