โญ๏ธ ๋ฌธ์์ด ๊ฐ์ฒด ( includes ๋ฉ์๋ ) โญ๏ธ
01. ํ์ค ๋ด์ฅ ๊ฐ์ฒด์ ์ข ๋ฅ : ๋ฌธ์์ด ๊ฐ์ฒด
ํ์ค ๋ด์ฅ ๊ฐ์ฒด(Standard Built-in Object)๋ ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ๊ฐ์ง๊ณ ์๋ ๊ฐ์ฒด๋ค์ ๋งํ๋ฉฐ, ๋ค๋ฅธ ๊ฐ์ฒด์ ๊ธฐ์ด๊ฐ ๋๋ ํต์ฌ์ ์ธ ๊ฐ์ฒด ์
๋๋ค.
๋ด์ฅ ๊ฐ์ฒด์ ์ข
๋ฅ์๋ Object, Fuction, String, Array, Math, Number, Event, Boolean, Data, RegExp ๋ฑ์ด ์์ต๋๋ค.
๊ทธ ์ค์์ ๋ฌธ์์ด ๊ฐ์ฒด(String Object)๋ ๋ฌธ์์ด์ ์ ์ฅ/๊ด๋ฆฌํ๊ธฐ ์ํด ์ฌ์ฉํ๋ ๊ฐ์ฒด๋ฅผ ์๋ฏธํฉ๋๋ค.
___ ์ฐธ๊ณ ํ๊ธฐ ___
`1 ๋ฌธ์์ด์ ์์ฑํ ๋๋ ''"" ๋ฐ์ดํ๋ฅผ ์ฌ์ฉํ๊ฑฐ๋, new ํค์๋๋ฅผ ์ด์ฉํฉ๋๋ค.
`2 ๋ฌธ์์ด ๊ฐ์ฒด๋ ๋ถ๋ณ์ฑ์ด ์์ผ๋ฉฐ, ์ด๋ก์จ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ ์ ์ฝ๊ณผ ๋ณด์์ฑ ๋ฐ ๋์์ฑ์ ํน์ง๋ ํจ๊ป ๊ฐ์ต๋๋ค.
02. includes ๋ฉ์๋
includes( ) ๋ฉ์๋๋ ๋ฌธ์์ด์ด ํน์ ๋ฌธ์์ด์ ํฌํจํ๋์ง ํ์ธํ์ฌ, ํฌํจ ์ฌ๋ถ๋ฅผ ๋ถ๋ฆฐ(true, false)๊ฐ์ผ๋ก ๋ฐํํฉ๋๋ค.
์์ ์์น๊ฐ์ ์ค์ ํ๋ฉด, ์์๋๋ ์์น๋ถํฐ ๋ง์ง๋ง ์์น๊น์ง์ ๋ฌธ์์ด ๋ฒ์์์ ํน์ ๋ฌธ์๋ฅผ ์ฐพ์ต๋๋ค.
[1] includes( ) ๋ฉ์๋์ ํ์
"๋ฌธ์์ด".includes(๊ฒ์๊ฐ, ์์ ์์น๊ฐ);
// includes( ) ๋ฉ์๋์ ๋ฆฌํด ----------------------------------------------------------------
const str1 = "javascript reference";
const currentStr1 = str1.includes("javascript"); // true
const currentStr2 = str1.includes("j"); // true
const currentStr3 = str1.includes("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 // eference ์์ reference ๋ฅผ ์ฐพ์ ์ ์์ผ๋ฏ๋ก false
'Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
search / march / charAt ๋ฉ์๋ (3) | 2022.08.23 |
---|---|
ํจ์์ ์ ํ (2) | 2022.08.23 |
๋ฌธ์์ด ๊ฐ์ฒด (8) indexOf / lastindexOf ๋ฉ์๋ (2) | 2022.08.18 |
๋ฌธ์์ด ๊ฐ์ฒด (7) padStart / padEnd ๋ฉ์๋ (2) | 2022.08.18 |
๋ฌธ์์ด ๊ฐ์ฒด (6) concat / repeat ๋ฉ์๋ (2) | 2022.08.18 |
๋๊ธ