728x90
์ฐพ๊ธฐ ->
.indexof ("๋ฌธ์");
.search ("๋ฌธ์์ด);
๊ฐ๊ณ ์ค๊ธฐ ->
.slice (์ซ์X๋ถํฐ , ์ซ์X๊น์ง)
.substring (์์ ๋์ผ)
.split (X ๋ถํฐ ์๋ฅด๊ธฐ)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p id="demo"></p>
<h3 id="h3">์ต๊ทผ SNS ์์ '#์ฌ์ฅ๋ํ๋ด์ธ์' ํด์ํ๊ทธ๋ฅผ ๋ฌ๊ณ ์๊ธฐ๋ก ์ง์ ์ด ๊ฐ์ ์์๋ฌธ๊ตฌ๋ฅผ ์ด ์์์ฆ ์ฌ์ง์ด ์ค์ง์ด ์ฌ๋ผ์ค๊ณ ์๋ค. ์ฝ๋ก๋ ๋๋ฌธ์ ์ฌ์ ์ด ์ด๋ ค์์ง ๋๋ค ๊ฐ๊ฒ์ ์์์ ์ฃผ๋ฌธํ๊ณ ์์์ฆ๊ณผ ์ธ์ฆ ์ฌ์ง์ ์ฐ์ด ์์์
์๋ค์ ์์ํ๋ ์ด๋์ด ๋ฒ์ด์ง ๊ฒ์ด๋ค.</h3>
<script type="text/javascript">
let str = document.getElementById("h3").innerHTML;
//alert(str);
// string
let pos = str.indexOf("์ต"); //๋ฌธ์์ ์์น indexof
pos = str.search("์ฌ์ฅ๋"); //๋ฌธ์์ด์ ์์น search
pos = str.slice(3,6); // 3๋ฒ์ง ~ 6๋ฒ์ง ์ ๊น์ง (substring๊ณผ ๋น์ท)
pos = str.substring(3, 6);
//let mystr= "ํด์ํ๊ทธ";
//str.slice(str.search(mystr),pos+str.length+1);
document.getElementById("demo").innerHTML = pos;
let str1, str2;
str1 = "hello";
str2 = "hell";
str2 = str2+"o";
if(str1==str2){
//alert("๊ฐ์ ๋ฌธ์์ด์
๋๋ค")
}
str = 'aa,bb,cc,dd';
let arr = str.split(','); // , == token
alert(arr[0]);
</script>
</body>
</html>
๋๊ธ