์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ฉ์๋ : includes()
์ด๋ฒ ์๊ฐ์๋ ๋ฌธ์์ด ๋ฉ์๋์ธ includes()์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค! ๐
#1. includes( )
includes() ๋ฉ์๋๋ ๋ฌธ์์ด ํฌํจ ์ฌ๋ถ๋ฅผ ๊ฒ์ํ์ฌ, ๋ถ๋ฆฐ(true, false)์ ๋ฐํํฉ๋๋ค. ์ฆ ๋ฌธ์์ด์ด ํน์ ๋ฌธ์์ด์ ํฌํจํ๋์ง ํ์ธํ๋ ๋ฉ์๋๋ผ ๋ณผ ์ ์์ต๋๋ค!
! includes( ) ์ฌ์ฉ ๋ฐฉ๋ฒ !
string.includes( searchString, length )
"๋ฌธ์์ด".includes(๊ฒ์ํ ๋ฌธ์์ด);
"๋ฌธ์์ด".includes(๊ฒ์ํ ๋ฌธ์์ด, ๊ฒ์์ ์์ํ ์์น); == indexOF()์ ๊ฑฐ์ ๊ฐ๋ค.
const str1 = "javascript reference";
const currentStr1 = str1.includes("javascript"); // true
const currentStr2= str1.includes("j"); // true
const currentStr3= str1.includes("b"); // false : b๋ ํฌํจ๋์ด ์์ง ์์ผ๋ฏ๋ก false
const currentStr4= str1.includes("reference"); // true
const currentStr5 = str1.includes("reference", 1); // true
const currentStr6 = str1.includes("reference", 11); // true
const currentStr7 = str1.includes("reference", 12); // false : ๋ฌธ์์ด ์์ฒด์ ์์น๊ฐ์ธ 12๊ฐ ์๊ธฐ ๋๋ฌธ์ false
! point !
'abzcd'.includes( 'z' )
includes() ๋ฉ์๋๊ฐ ๋ฌธ์์ด์ธ 'abzcd'์์ z๋ฅผ ํฌํจํ๋์ง ๊ฒ์ฌํ๋ค. ์ ์์ z๋ฅผ ํฌํจํ๋ฏ๋ก true๋ฅผ ๋ฐํํ๋ค!
'abZcd'.includes( 'z', 3 )
includes() ๋ฉ์๋๊ฐ ๋ฌธ์์ด์ธ 'abZcd'์ 3๋ฒ์งธ ์์น๋ถํฐ z๋ฅผ ํฌํจํ๋์ง ๊ฒ์ฌํ๋ค. includes()๋ ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ๊ธฐ ๋๋ฌธ์ z๋ฅผ ํฌํจํ์ง ์์ผ๋ฏ๋ก false๋ฅผ ๋ฐํํ๋ค!
'JAVASCRIPT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVASCRIPT] ๋ฌธ์์ด ๋ฉ์๋ : match( ) (1) | 2022.08.23 |
---|---|
[JAVASCRIPT] ๋ฌธ์์ด ๋ฉ์๋ : search( ) (1) | 2022.08.23 |
[JAVASCRIPT] ๋ฌธ์์ด ๋ฉ์๋ : padStart( ) / padEnd( ) (3) | 2022.08.18 |
[JAVASCRIPT] ๋ฌธ์์ด ๋ฉ์๋ : repeat( ) (2) | 2022.08.18 |
[JAVASCRIPT] ๋ฌธ์์ด ๋ฉ์๋ : concat( ) (2) | 2022.08.18 |
๋๊ธ