๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
JAVASCRIPT

[JAVASCRIPT] ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : search( )

by _ํ† ๋งคํ†  2022. 8. 23.
728x90

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ : ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : search()

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ์ธ search()์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ๐Ÿ˜


#1. search( )

search() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์„ ์ฃผ์–ด์ง„ ํšŸ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•ด ๋ถ™์ธ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

! search( ) ์‚ฌ์šฉ ๋ฐฉ๋ฒ• !
"๋ฌธ์ž์—ด".search(๊ฒ€์ƒ‰๊ฐ’);
"๋ฌธ์ž์—ด".search(์ •๊ทœ์‹ ํ‘œํ˜„);

const str1 = "javascript reference";

const currentStr1 = str1.search("javascript");      // 0
const currentStr2 = str1.search("reference");       // 11 (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 (๋ฌธ์ž์—ด์— ์—†์„ ๊ฒฝ์šฐ ์Œ์ˆ˜ -1์ด ๋‚˜์˜ด)
const currentStr7 = str1.search("b");               // -1
const currentStr8 = str1.search(/[a-z]/g);          // 0 //j๊ฐ€ a๋ถ€ํ„ฐ z๊นŒ์ง€ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ๊ฐ€์žฅ ์ฒซ๋ฒˆ์งธ ๊ฐ’์˜ ์œ„์น˜๋งŒ ์ถœ๋ ฅ

! point ! indexOF()๋ณด๋‹ค search()๋ฅผ ๋” ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ž˜ ์•Œ์•„๋‘์ž!

728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css