λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
JAVASCRIPT

[JAVASCRIPT] λ¬Έμžμ—΄ λ©”μ„œλ“œ : match( )

by _토맀토 2022. 8. 23.
728x90

μžλ°”μŠ€ν¬λ¦½νŠΈ : λ¬Έμžμ—΄ λ©”μ„œλ“œ : match()

이번 μ‹œκ°„μ—λŠ” λ¬Έμžμ—΄ λ©”μ„œλ“œμΈ match()에 λŒ€ν•΄ μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€! 😁


#1. match( )

match() λ©”μ„œλ“œλŠ” λ¬Έμžμ—΄μ„ κ²€μƒ‰ν•˜κ³  배열을 λ°˜ν™˜ν•©λ‹ˆλ‹€.

! match( ) μ‚¬μš© 방법 !
"λ¬Έμžμ—΄".math(검색값);
"λ¬Έμžμ—΄".math(μ •κ·œμ‹ ν‘œν˜„);

const str1 = "javascript reference";

const currentStr1 = str1.math("javascript");    // javascript
const currentStr2 = str1.math("reference");     // reference
const currentStr3 = str1.math("r");             // r
const currentStr4 = str1.math(/reference/);     // reference
const currentStr5 = str1.math(/Reference/);     // null
const currentStr6 = str1.math(/Reference/i);    // reference
const currentStr7 = str1.math(/r/g);            // ['r', 'r', 'r']
const currentStr8 = str1.math(/e/g);            // ['e', 'e', 'e', 'e']

! point ! λŒ€μ†Œλ¬Έμžλ₯Ό κ΅¬λΆ„ν•˜λ©° λ¬Έμžμ—΄μ— 검색값이 없을 경우 null이 λ°˜ν™˜λœλ‹€!

728x90

λŒ“κΈ€


Lucky Charms Rainbow
js
html
css