728x90
๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : includes()
includes() ๋ฉ์๋๋ ๋ฌธ์์ ํฌํจ ์ฌ๋ถ๋ฅผ ๊ฒ์ํ์ฌ, ๋ถ๋ฆฐ(true, false)์ ๋ฐํํฉ๋๋ค. ์ฆ, ๋ฐฐ์ด์ด ํน์ ์์๋ฅผ ํฌํจํ๊ณ ์๋์ง ํ๋ณํฉ๋๋ค.
includes() ๋ฉ์๋
์ฐธ๊ณ !
includes() ๋ฉ์๋๋ ๋/์๋ฌธ์๋ฅผ ๊ตฌ๋ถํฉ๋๋ค.
1. "๋ฌธ์์ด".includes("๊ฒ์๊ฐ")
const str1 = "javascript reference";
const currentStr1 = str1.includes("javascript");
const currentStr2 = str1.includes("j");
const currentStr3 = str1.includes("b");
๊ฒฐ๊ณผ๋ณด๊ธฐ
true
true
false
true
false
2. "๋ฌธ์์ด".includes("๊ฒ์๊ฐ", ์์น๊ฐ)
์์น๊ฐ์ ์์ฑํ๋ฉด, ์์น๊ฐ์ ๊ธฐ์ค์ผ๋ก ๊ฒ์์ ์์ํฉ๋๋ค.
const str1 = "javascript reference";
const currentStr4 = str1.includes("reference");
const currentStr5 = str1.includes("reference", 1);
const currentStr6 = str1.includes("reference", 11);
const currentStr7 = str1.includes("reference", 12);
๊ฒฐ๊ณผ๋ณด๊ธฐ
true
true
true
false
true
true
false
728x90
'Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : match() (9) | 2022.08.22 |
---|---|
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : search() (9) | 2022.08.22 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : padStart() / padEnd() (5) | 2022.08.17 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : split() (5) | 2022.08.17 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : repeat() (5) | 2022.08.17 |
๋๊ธ