Get first n characters of string JavaScript | Example code

You can use substring or slice method to Get first n characters of string in JavaScript. Where n could be any number 1,2,3… so on. Get first n characters of string JavaScript Examples HTML examples code: Let’s get first 4 char from string in JS. Using substring() Method:

Using slice() Method:

Output: Result Read More…


Get the first character of string JavaScript | example code

The simplest way to get the first character of the given string in JavaScript is charAt method. This method returns the character at the specified index in a string. Another way is the substring method to extracts the characters from a string, between two specified indices. Get the first character of string JavaScript Examples HTML Read More…


Get the middle character JavaScript | Extracting middle of a string example

Get the middle character JavaScript Example code: Let’s Create a function that returns the middle character/s of a sentence.

Output: Do comment if you have any doubts and suggestions on this example code. RohitDegree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.