cording/생활코딩
[Java Script] 배열
효기롭다
2022. 3. 7. 01:36
배열이란 연관된 데이터를 정리해서 담아두는 상자이다
*이때, [] 의 기호를 사용한다.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Array</h1>
<h2>Syntax</h2>
<script>
var coworkers = ["egoing", "leezche"];
</script>
<h2>get</h2>
<script>
document.write(coworkers[0]);
document.write(coworkers[1]);
</script>
<h2>add</h2>
<script>
coworkers.push('hyogii')
coworkers.push('s.coups')
</script>
<h2>count</h2>
<script>
document.write(coworkers.length);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Array</h1>
<h2>Syntax</h2>
<script>
var coworkers = ["egoing", "leezche"]; : coworkers = ( 대입한다 ) ["egoing", "leezche"]
</script>
<h2>get</h2>
<script>
document.write(coworkers[0]); : coworkers의 [0]번 (첫번째)
document.write(coworkers[1]); : coworkers의 [1]번 (두번째)
</script>
<h2>add</h2>
<script>
coworkers.push('hyogii') : push 배열추가 (이름)
coworkers.push('s.coups')
</script>
<h2>count</h2>
<script>
document.write(coworkers.length); : length 문자열의 길이를 구함
</script>
</body>
</html>
결과물