๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

search()

by Youcodein 2022. 8. 22.
728x90
๋ฐ˜์‘ํ˜•

search() : ๋ฌธ์ž์—ด์„ ๊ฒ€์ƒ‰(์ •๊ทœ์‹) : ๋ฐ˜ํ™˜(์ˆซ์ž)

search() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด(์ •๊ทœ์‹)์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์œ„์น˜๊ฐ’(์ˆซ์ž)๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

"๋ฌธ์ž์—ด".search("๊ฒ€์ƒ‰๊ฐ’");
"๋ฌธ์ž์—ด".search(์ •๊ทœ์‹ ํ‘œํ˜„);
const str1 = "javascript reference";
    
const currentStr1 = str1.search('javascript');            //0
const currentStr2 = str1.search('reference');          //11
const currentStr3 = str1.search('j');                  //0
const currentStr4 = str1.search('a');                  //1
const currentStr5 = str1.search('v');                  //2
const currentStr6 = str1.search('jquery');             //-1(๋ฐ์ดํ„ฐ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ ์ด๋ ‡๊ฒŒ ์ถœ๋ ฅ๋จ)
const currentStr7 = str1.search('b');                  //-1(๋ฐ์ดํ„ฐ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ ์ด๋ ‡๊ฒŒ ์ถœ๋ ฅ๋จ)
const currentStr8 = str1.search(/[a-z]/g);                  //0
728x90
๋ฐ˜์‘ํ˜•

'์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

charAt()  (7) 2022.08.22
match()  (6) 2022.08.22
includes()  (5) 2022.08.17
padStart() / padEnd()  (5) 2022.08.17
replace() / replaceAll()  (4) 2022.08.17

๋Œ“๊ธ€