# 반복문 내장함수(응용)1

## 1) 실습과제

```javascript
const items = [
    {
        id: 1,
        name: '아이언맨'
    },
    {
        id: 2,
        name: '캡틴 아메리카'
    },
    {
        id: 3,
        name: '토르'
    },
    {
        id: 4,
        name: '닥터 스트레이지'
    }
];
```

```javascript
const jsonadd = function(props, adds) {    //JSON 코드에 data(원소들)밑에 추가하는 기능
    items.forEach((data) => {
        if(data.id == 2){
            data[props] = adds;
            return false;
        }
    });
};
jsonadd('strint', 'love')
jsonadd('lite', 'triplexlab')
// console.log(items);

const jsonupdate = function(id, names){  //JSON 코드에 data(원소들)를 수정하는 기능
    items.forEach((data) => {
        if (data.id == 2) {
            data.name = names;
            return false;
        }
    });
};
jsonupdate(2, 'thdbsgh3443');
// console.log(items);

const jsondelete = function(id, names){  //JSON 코드에 data(원소들)를 삭제하는 기능
    items.forEach((data) => {
        if(data.id == 2){
            delete data.name;
            return false;
        }
    });
};
jsondelete(2, 'thdbsgh344')
// console.log(items);
```

{% file src="/files/-M2Lv\_cz95iqYkqusFqM" %}
반복문내장함수-forEach
{% endfile %}


---

# Agent Instructions: 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:

```
GET https://triplexlab.gitbook.io/vanilla-js/practice/practice-for-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
