> For the complete documentation index, see [llms.txt](https://westsilver.gitbook.io/study-script/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://westsilver.gitbook.io/study-script/javascript/basic/untitled-2.md).

# 배열과 반복문

### 1. 배열과 반복문의 기본

### 예시)

![](/files/-Mj3zYXOKWFiPxbGjsZz)

{% tabs %}
{% tab title="basic" %}

```javascript
<h1>Loop & Array</h1>
<script>
    var coworkers = ['west', 'sliver', 'red', 'cho'];
</script>
<h2>Co workers</h2>
<ul>
    <script>
        var i = 0;
        while(i < 4){
            document.write('<li>'+coworkers[i]+'</li>');
            i = i + 1;
        }
    </script>
</ul>
```

{% endtab %}
{% endtabs %}

### 2. 데이터 추가/ 제거에 유동적으로 실행되는 반복문

### 예시)

![](/files/-Mj3z2RjPCVawNctoYkS)

![](/files/-Mj3zb1qJD48x6qUe4d1)

```javascript
<h1>Loop & Array</h1>
<script>
    var coworkers = ['west', 'sliver', 'red', 'cho', 'seoeun'];
</script>
<h2>Co workers</h2>
<ul>
    <script>
        var i = 0;
        while(i < coworkers.length){
            document.write('<li>'+coworkers[i]+'</li>');
            i = i + 1;
        }
    </script>
</ul>
```

{% hint style="success" %}
데이터의 개수가 달라졌을 때를 대비하여 반복문의 조건을 '변수명.length' 로 대입
{% endhint %}

### 3. 데이터에 a링크를 추가하고 싶을 때

### 예시)

![](/files/-Mj3z5a_HqbwRqk3wNGF)

![](/files/-Mj3zew-fcSo2M9PirCV)

```javascript
<h1>Loop & Array</h1>
<script>
    var coworkers = ['west', 'sliver', 'red', 'cho', 'seoeun'];
</script>
<h2>Co workers</h2>
<ul>
    <script>
        var i = 0;
        while(i < coworkers.length){
            document.write('<li><a href="http://a.com/'+coworkers[i]+'">'+coworkers[i]+'<a/></li>');
            i = i + 1;
        }
    </script>
</ul>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://westsilver.gitbook.io/study-script/javascript/basic/untitled-2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
