JS String 객체/프로퍼티 ("", '', .length,)
2021. 7. 30. 22:26
728x90
01 문자열 표현 ("") / ('')
문자열은 큰따옴표("")나 작은따옴표('')를 사용
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>string</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script>
var str = "모든 국민은 법률이 정하는 바에 의하여 국방의 의무를 진다.";
document.write(str)
</script>
</head>
<body>
</body>
</html>
02 문자열 길이 (.length)
문자열 내의 문자 갯수를 반환. 문자열의 길이는 length 프로퍼티로 저장.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>string</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script>
var str1 = "Hello";
document.write(`${str1} 의 문자 갯수는 ${str1.length}<br>`);
var str2 = "안녕하세요";
document.write(`${str2} 의 문자 갯수는 ${str2.length}`);
</script>
</head>
<body>
</body>
</html>
728x90
'JavaScript > Study' 카테고리의 다른 글
[JS] 배열 (array, arr.push) (0) | 2021.07.30 |
---|---|
[JS] String 메소드 (str.charAt, str.substring, str.indexOf, str.replace, str.replaceAll) (0) | 2021.07.30 |
JS Math 프로퍼티 (Math.PI) (0) | 2021.07.30 |
JS Math 메소드 (Math.max, Math.min, Math.random, Math.round, Math.floor, Math.ceil, Math.trunc) (0) | 2021.07.25 |
[JS] Date 메소드 (Date.now, Date.prototype getter, Date.prototype setter) (0) | 2021.07.24 |