배열이란 연관된 데이터를 정리해서 담아두는 상자이다
*이때, [] 의 기호를 사용한다.
<!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>
결과물
'cording > 생활코딩' 카테고리의 다른 글
[Java Script] 배열과 반복문 (0) | 2022.03.09 |
---|---|
[Java Script] 반복문 (0) | 2022.03.07 |
[Java Script] 리팩토링 중복의 제거 (0) | 2022.03.06 |
[Java Script] 조건문의 활용 (0) | 2022.03.05 |
[Java Script] 비교연산자 (0) | 2022.03.03 |