

I did not mention it, but at this point it is almost an unspoken rule: if we deal with indexes or positions, we always use code units.

Okay, this was all nice, but let’s move to the more serious business of dealing with code units and code points. Cause you know what they say? Silly mistakes are the hardest ones to find. This is quite clear, so no need to dissect it any further. searchedString.includes("Dev") // false searchedString.includes("dev") // true searchedString.includes("hello") // false searchedString.includes("Hello") // true searchedString.includes("NEWBS") // false searchedString.includes("newbs") // trueįirst version for each searched string is incorrect because of case-sensitivity. Let’s see what I am talking about in an example 2. If you try to search for those, keep this in mind. Which means that it differentiates between lowercase and uppercase of alphabet characters. I mentioned it already, but this is a common case of errors, so I will emphasize it once again. The last result is false, because index 12 that we specified causes the searched string to start in the middle of the word “fellow” which means that we can not find the whole word in a specified range.

let searchedString = "Hello my fellow dev newbs! 🙂" let stringToLookFor = "fellow" searchedString.includes(stringToLookFor) // true searchedString.includes(stringToLookFor, 9) // true searchedString.includes(stringToLookFor, 12) // falseįirst and second result is true because the range used for searching includes the string “fellow” we are checking for occurence. Let’s see how it all works in the first example. If it is not provided, it defaults to value 0. Second parameter is optional and specifies the position to start the search. First parameter is required and it is the value of string that is being checked for occurence in searched string. Returning value can either be true or false based on a result of search. The includes() method performs a case-sensitive search to determine whether a specified string may be found within the searched string. Topic of this lovely day is method includes(). Hello my fellow dev newbs and welcome back to the Javascript Basics series about built-in object String.
