자바스크립트 배열

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<style>
body{
    padding: 20px;
}
ul{
    font-size: 20px;
}
</style>
</head>
<body>
    <h1>자바스크립트 배열(Array)</h1>
    <ul>
        <li id="a0">x</li>
        <li id="a1">x</li>
        <li id="a2">x</li>
        <li id="a3">x</li>
        <li id="a4">x</li>
        <li id="a5">x</li>
        <li id="a6">x</li>
    </ul>

<script>
    var arr = ['A', 'B', 'C', 'D', 'E'];
    arr.push('F', 'G');
    
    for(var i= 0 ; i<arr.length ; i++){
    document.getElementById('a'+i).innerText = arr[i];
    }
</script>  
</body>
</html>

 

result
결과