Last active
October 10, 2020 09:59
-
-
Save YakovSPb/0a48aa3edcc390724260ece4291571a5 to your computer and use it in GitHub Desktop.
JS найти, что строка содержит подстроку
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JS найти, что строка содержит подстроку | |
======================== | |
1. Первый вариант includes | |
let string = 'crossroad'; | |
let substring = 'roads'; | |
let result1 = string.includes(substing); | |
2. Второй вариант infexOf | |
let string = 'crossroad'; | |
let substring = 'roads'; | |
let result2 = string.indexOf(substing) !== -1; | |
3. Третий вариант regExp | |
let string = 'crossroad'; | |
let substring = 'roads'; | |
let regExp = /road/; | |
let result3 = regExp.test(string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment