There are a number of methods that we can work with when it comes to strings in Javascript. The methods I am going to discuss have to do with finding specific words or characters within a string.
indexOf(SearchString, Position);
const text = "Some long text ..."
const startPosition = 6;
indexOf(text, startPosition);
The indexOf method will return the index of first occurrence of specified String starting from specified number index. This method takes two parameters, the first is the string that you want to search for and the second is an int that references the position in the string, that is being searched, where it will start. If nothing is found it will return -1, otherwise it returns an int representing the position in the string where the search term was found. This would be useful for searching through a large block of text. Obtaining the position will help when combined with the next command, substring.
substring(start, end);
const startPosition = 6;
const endPosition = 12;
const newString = substring(startPosition, endPosition);
The substring method will take whatever is within the start and ending positions in the string and return a new string with that value. The parameters being passed in are two ints referring to the starting and ending positions, where the new string is being copied out of the larger string. This could be useful when combined with the previous command in order to extract a specific phrase or quote.
replace(searchValue, replaceValue);
const searchWord = "John";
const replaceWord = "Jack";
replace(searchWord, replaceWord);
The replace method will search a string for a specific value and if it encounters that value it will replace it. This method takes two strings as parameters. The first is what is being searched for and the second is what it is being replaced with. This is very useful. Find and replace are tools often found in text editors. This tool makes replacing the name of a person or business in a string fast and easy. It would be easy to overlook one instance of a word, so this would insure that every instance is changed. This would help with forms and templates, where being professional matters.