# 표준 내장 객체의 확장

## 표준 내장 객체(Standard Built-in Object)

**자바스크립트가 기본적으로 가지고 있는 객체들을 의미한다. 호스트 환경에서 미리 만들어진 객체를 의미**

객체가 중요한 이유는 프로그래밍을 하는데 기본적으로 필요한 도구들이기 때문에다.

### 자바스크립트 내장 객체

* Object
* Function
* Array
* String
* Boolean
* Number
* Math
* Date
* RegExp

### 배열을 확장

```javascript
var arr = new Array('seoul','new york','ladarkh','pusan', 'Tsukuba');
function getRandomValueFromArray(haystack){
    var index = Math.floor(haystack.length*Math.random()); 
    // random -> 0 부터 1 사이에 있는 소수 값들중 하나를 곱하면 그값을 최대값으로 하는 랜덤한 값을 만들어낸다.
    //floor -> 어떠한 소수점이 을때 뒤에 있는 값을 없애줌
    return haystack[index]; 
}
console.log(getRandomValueFromArray(arr)); //렌덤하게 만들어낸 index에 해당하는 임의의값이 출력
```

이 함수를 **배열 객체에 포함**시키는 것이다. 그렇게하면 마치 배열에 내장된 메소드인 것처럼 위의 기능을 사용할 수 있다.

```javascript
Array.prototype.random = function(){ // Array 배열을 만드는 생성자 
    var index = Math.floor(this.length*Math.random()); // this는 배열객체을 받음
    return this[index];
}
var arr = new Array('seoul','new york','ladarkh','pusan', 'Tsukuba');
console.log(arr.random()); //렌덤하게 만들어낸 index에 해당하는 임의의값이 출력
// 가독성이 더 높아짐 배열에 random이 소속되어있기때문에 
```


---

# 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://leeboa.gitbook.io/study/undefined-13/undefined-11/undefined-2.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.
