Reverse string in JavaScript | Using for loop and inbuilt methods examples

There are serval ways to do Reverse string in JavaScript. The most common ways are using Using for Loop and built-in Methods (split, array revers and join). Reverse string in JavaScript Examples HTML examples: Using for Loop Inside function created empty “newString” variable. In for loop add last item first position in the new string, Read More…


JavaScript split a string at the index | Particular and nth position example

Use substring method to split a string at the index in JavaScript. You can also create function for it. JavaScript split the string at index Example code HTML example code: How do split a string at a particular index? e.g split string at index 10, making the string now equal to everything up to index Read More…


JavaScript get the first 3 characters of a string | HTML example code

Use slice method to get first 3 characters of a string in JavaScript. JavaScript get first 3 characters of string Example A slice(begin, end) method works on strings, as well as arrays. It returns a string representing the substring of the original string, from beginning to end (end not included) where to begin and to Read More…


Get the first two characters of string JavaScript | Example code

Get first two characters of string JavaScript HTML example code You can use inbuilt slice method to get first 2 characters of a string in JavaScript. Pass index value 0 for start and 1 for end. Output: Do comment if you have any doubts and suggestions on this JS char topic. RohitDegree in Computer Science Read More…


JavaScript split a sentence into words | Example code

Just use the split method to split a sentence into words in JavaScript. You can also use it for loop iteration. In both ways, you have to use the space option for separating normal sentences. JavaScript split the sentence into words Example code HTML example code:- Using split method It will return array without space. Read More…


Loop through words in a string JavaScript | Iterate words in a string in JS

Simple for loop can use for in Loop through words in a string JavaScript. And for iterate words in string use split, map, and join methods (functions). Loop through words in a string JavaScript Example Output: Iterate words in string in JS Example code Output: Do comment if you have any doubts and suggestion on Read More…


Get word from string JavaScript | Extract a specific word example

Use split and some function or regex with word boundaries to find or Extract a specific word from string in JavaScript. Get word from string JavaScript Example HTML example code: Match if word present in given string. Using split and some function If word found then return true. Using a regex with word boundaries: Output: Read More…


Get the first word of string JavaScript | Example code

Use split method with 0 indexes to get the only first word of string in JavaScript. The split method returns an array, so you can easily get the first element. Get the first word of string JavaScript example HTML example code: You need to split the string by space and the get only 0 index Read More…


Get the last word from string JavaScript | Example code

Use Regular expression or with replace and split method to get the last word from string JavaScript. It’s not the only way to get the last word from the string you can use split or inbuilt lastIndexof with the substring method. Get the last word from string JavaScript example code HTML example code:- Regular expression Read More…


JavaScript remove the last word from a string | Example code

The simplest way to get remove the last word from a string in JavaScript Using string.substring() Function. There are many ways and methods. We will see the other method with examples in this tutorial. JavaScript remove the last word from a string Example HTML example code:- Using substring() Function  The lastIndexOf() function is used to Read More…