728x90
λ°μν
1. λ¬Έμμ΄ λ©μλ : λ³κ²½ : slice() : λ¬Έμμ΄μμ μνλ κ°μ μΆμΆ
slice() : λ¬Έμμ΄μμ μνλ κ°μ μΆμΆν©λλ€.
//slice(μμ μμΉ)
//slice(μμ μμΉ, λλλ μμΉ)//λλλ μμΉ κ°μ΄ μμ μμΉ κ°λ³΄λ€ 컀μΌν¨
//substr(μμμμΉ)
//substr(μμμμΉ, κΈΈμ΄)
const str1 = "javascript reference";
const currentStr1 = str1.slice(0); //javascript reference
const currentStr2 = str1.slice(1); //avascript reference
const currentStr3 = str1.slice(2); //vascript reference
const currentStr4 = str1.slice(0, 1); //j
const currentStr5 = str1.slice(0, 2); //ja
const currentStr6 = str1.slice(0, 3); //jav
const currentStr7 = str1.slice(1, 2); //av
const currentStr8 = str1.slice(1, 3); //av
const currentStr9 = str1.slice(1, 4); //avs
const currentStr10 = str1.slice(-1); //e
const currentStr11 = str1.slice(-2); //ce
const currentStr12 = str1.slice(-3); //nce
const currentStr13 = str1.slice(-3, -1); //nc
const currentStr14 = str1.slice(-3, -2); //n
const currentStr15 = str1.slice(-3, -3); //n
const currentStr16 = str1.slice(1, 4); //ava
const currentStr17 = str1.slice(4, 1); //''
const currentStr18 = str1.substring(4, 1); //ava
const currentStr19 = str1.substring(1, 4); //ava
//substring()μ μμ μμΉμ λλλ μμΉκ°μ ν¬κΈ°μ μν₯μ΄ μλ€. μλμΌλ‘ λ°κΏμ€
const currentStr20 = str1.substr(0); //javascript reference
const currentStr21 = str1.substr(1); //avascript reference
const currentStr22 = str1.substr(2); //vascript reference
const currentStr23 = str1.substr(0, 1); //j
const currentStr24 = str1.substr(0, 2); //ja
const currentStr25 = str1.substr(0, 3); //jav
const currentStr26 = str1.substr(1, 2); //av
const currentStr27 = str1.substr(1, 3); //ava
const currentStr28 = str1.substr(1, 4); //avas
const currentStr29 = str1.substr(-1); //e
const currentStr30 = str1.substr(-2); //ce
const currentStr31 = str1.substr(-3); //nce
const currentStr32 = str1.substr(-1, 1); //e
const currentStr33 = str1.substr(-2, 2); //ce
const currentStr34 = str1.substr(-3, 3); //nce
02. λ¬Έμμ΄ λ©μλ : slice() substring() substr()
λ¬Έμμ΄μμ μνλ κ°μ μΆμΆνμ¬ λ¬Έμμ΄μ λ°ννλ λ©μλμ λλ€.
"λ¬Έμ§μ΄".slice(μμ μμΉ)
"λ¬Έμ§μ΄".slice(μμ μμΉ, λλλ μμΉ)
//λλλ μμΉ κ°μ΄ μμ μμΉ κ°λ³΄λ€ 컀μΌν¨
//substring()μ μμκ°μ΄ λλλ κ°λ³΄λ€ ν΄ κ²½μ° λ κ°μ λ°κΏμ μ²λ¦¬(μλ¬λ°©μ§) "λ¬Έμ§μ΄".substr(μμμμΉ)
"λ¬Έμ§μ΄".substr(μμμμΉ, κΈΈμ΄)
"λ¬Έμ§μ΄".slice(μμ μμΉ, λλλ μμΉ)
//λλλ μμΉ κ°μ΄ μμ μμΉ κ°λ³΄λ€ 컀μΌν¨
//substring()μ μμκ°μ΄ λλλ κ°λ³΄λ€ ν΄ κ²½μ° λ κ°μ λ°κΏμ μ²λ¦¬(μλ¬λ°©μ§) "λ¬Έμ§μ΄".substr(μμμμΉ)
"λ¬Έμ§μ΄".substr(μμμμΉ, κΈΈμ΄)
//slice(μμ μμΉ)
//slice(μμ μμΉ, λλλ μμΉ)//λλλ μμΉ κ°μ΄ μμ μμΉ κ°λ³΄λ€ 컀μΌν¨
//substr(μμμμΉ)
//substr(μμμμΉ, κΈΈμ΄)
const str1 = "javascript reference";
const currentStr1 = str1.slice(0); //javascript reference
const currentStr2 = str1.slice(1); //avascript reference
const currentStr3 = str1.slice(2); //vascript reference
const currentStr4 = str1.slice(0, 1); //j
const currentStr5 = str1.slice(0, 2); //ja
const currentStr6 = str1.slice(0, 3); //jav
const currentStr7 = str1.slice(1, 2); //av
const currentStr8 = str1.slice(1, 3); //av
const currentStr9 = str1.slice(1, 4); //avs
const currentStr10 = str1.slice(-1); //e
const currentStr11 = str1.slice(-2); //ce
const currentStr12 = str1.slice(-3); //nce
const currentStr13 = str1.slice(-3, -1); //nc
const currentStr14 = str1.slice(-3, -2); //n
const currentStr15 = str1.slice(-3, -3); //n
const currentStr16 = str1.slice(1, 4); //ava
const currentStr17 = str1.slice(4, 1); //''
const currentStr18 = str1.substring(4, 1); //ava
const currentStr19 = str1.substring(1, 4); //ava
//substring()μ μμ μμΉμ λλλ μμΉκ°μ ν¬κΈ°μ μν₯μ΄ μλ€. μλμΌλ‘ λ°κΏμ€
const currentStr20 = str1.substr(0); //javascript reference
const currentStr21 = str1.substr(1); //avascript reference
const currentStr22 = str1.substr(2); //vascript reference
const currentStr23 = str1.substr(0, 1); //j
const currentStr24 = str1.substr(0, 2); //ja
const currentStr25 = str1.substr(0, 3); //jav
const currentStr26 = str1.substr(1, 2); //av
const currentStr27 = str1.substr(1, 3); //ava
const currentStr28 = str1.substr(1, 4); //avas
const currentStr29 = str1.substr(-1); //e
const currentStr30 = str1.substr(-2); //ce
const currentStr31 = str1.substr(-3); //nce
const currentStr32 = str1.substr(-1, 1); //e
const currentStr33 = str1.substr(-2, 2); //ce
const currentStr34 = str1.substr(-3, 3); //nce
728x90
λ°μν
'μλ°μ€ν¬λ¦½νΈ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
toUpperCase() / toLowerCase() (4) | 2022.08.17 |
---|---|
μ κ·ννμ (4) | 2022.08.17 |
indexOf()/lastIndexOf() (6) | 2022.08.17 |
λ΄μ₯ν¨μ (3) | 2022.08.15 |
λ°°μ΄ κ΄λ ¨ λ©μλ (10) | 2022.08.11 |
λκΈ