![]() ![]() } Option 2: Use the indexOf Method (ECMAScript 5 or older) run this code if People is present in the str constant ![]() const str = 'We the People of the United States, in Order to form a more perfect Union.' Ĭonsole.log(str.includes('We the')) // trueĬonsole.log(str.includes('Order')) // trueĬonsole.log(str.includes('notpresent')) // falseĬonsole.log(str.includes('WE THE')) // false The code snippet below shows you how to use the includes method to check if a string contains a substring in ECMAScript 6. Option 1: Use the includes Method (ECMAScript 6) One of the ways is done using the includes method for JavaScript 6 (ECMAScript 6) and the other is with the indexOf for JavaScript 5 (ECMAScript 5) or older. There are two simple ways to check if a string contains a substring in JavaScript. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |