본문 바로가기
정리_창고

JavaScript - Array Methods 사전식 정리

by SKim입니다 2020. 7. 4.

JavaScript 총정리 - 목차로 바로가기

 

concat()   arr.concat([value1[, value2[, ...[, valueN]]]])

 두 개 이상의 array들을 join한다.

더보기

리턴값: array들이 join된 array

array2, array3, ..., arrayX - join될 array들

* original array를 변경하지 않고, 새로운 array를 리턴한다.

 

var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var kai = ["Robin"];
var children = hege.concat(stale);

//  ["Cecilie", "Lone", "Emil", "Tobias", "Linus", "Robin"]

 

constructor   arr.constructor

 이 property는 array의 constructor 함수를 리턴한다.

더보기

리턴값: 그 함수의 이름이 아니라, 함수에 대한 reference

어떤 변수가 배열인지 체크하기 위해서 constructor property를 사용할 수 있다. 

 

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.constructor;

// function Array() { [native code] }

 

copyWithin()   arr.copyWithin(target[, start[, end]])

 array의 element들을 그 array의 다른 position으로 옮기고, 기존의 값들을 덮어쓴다.

 → array의 length는 변하지 않는다.

더보기

리턴값: 변경된 array

target - element들을 붙여넣을 index position

start - 어느 index position의 element부터 복사할 것인가 (디폴트: 0)

end - 어느 index position의 element 직전까지 복사할 것인가 (디폴트: arr.length)

 

var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi", "Papaya"];
fruits.copyWithin(2, 0, 2);

// ["Banana", "Orange", "Banana", "Orange", "Kiwi", "Papaya"]

 

entries()  arr.entries()

key/value 짝을 가진 Array Iterator를 리턴한다.

더보기

리턴값: An Array Iterator object

original array의 각각의 item에 대해서, 새로운 iteration object는, index를 key로 가지고, item value를 value로 가진 array를 contain한다.

[0, "Banana"]
[1, "Orange"]
[2, "Apple"]
[3, "Mango"]

* original array를 변경하지 않는다.

 

const array1 = ['a', 'b', 'c'];
const iterator1 = array1.entries();

console.log(iterator1.next().value);
// expected output: Array [0, "a"]

console.log(iterator1.next().value);
// expected output: Array [1, "b"]

 

every()   arr.every(callback(currentValue[, index[, arr]]) [, thisArg])

그 array 안의 모든 element들이 (함수 형태의) 테스트를 통과할 수 있는지 체크한다. (true/false)

더보기

리턴값: 불리언

callback - array의 각각의 element에 대해 실행시킬 함수

currentValue - 현재 element의 value

index - 현재 element의 array index

arr - 현재 element가 속한 array object

thisArg - 함수에 pass되어 그것의 "this" value로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다.

 

그 array 안에 있는 각각의 element에 대해서 함수를 한 번씩 실행시킨다.

- 함수가 false value를 리턴하는 element를 찾으면 false를 리턴하고  체크를 중단한다.

- false가 하나도 없다면 true를 리턴한다.

 

* value가 없는 element에 대해서는 함수를 실행시키지 않는다.

* 빈 배열에서 호출하면 무조건 true를 리턴한다.

* original array를 변경하지 않는다.

 

function isBigEnough(element, index, array) {
  return element >= 10;
}
[12, 5, 8, 130, 44].every(isBigEnough);   // false
[12, 54, 18, 130, 44].every(isBigEnough); // true
// arrow function으로
[12, 5, 8, 130, 44].every(x => x >= 10); // false
[12, 54, 18, 130, 44].every(x => x >= 10); // true
var survey = [
  { name: "Steve", answer: "Yes"},
  { name: "Jessica", answer: "Yes"},
  { name: "Peter", answer: "Yes"},
  { name: "Elaine", answer: "No"}
];

function isSameAnswer(el, index, arr) {
  if (index === 0){
    return true;
  } else {
    return (el.answer === arr[index - 1].answer);
  }
}

survey.every(isSameAnswer);

 

fill()  arr.fill(value[, start[, end]])

array 안에 있는 specified elements를 static value로 채운다. (original array를 덮어쓴다.)

더보기

리턴값: 변경된 array

value - array를 채울 value

start - array를 이 index부터 채운다. (디폴트: 0)

end - array를 이 index 직전까지 채운다. (디폴트: arr.length)

 

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi",2,4);

// ["Banana", "Orange", "Kiwi", "Kiwi"]

 

filter()  arr.filter(callback(element[, index[, array]])[, thisArg])

(함수로 제공된) 테스트를 통과한 모든 array elements로 채워진 array를 생성한다.

더보기

리턴값: 테스트통과한 모든 array element로 채워진 array. 만약 어떤 element도 테스트통과하지 못한다면, 빈 배열을 리턴한다.

callback - array 안의 각각의 element들에 대해서 실행될 함수

element - 현재 element의 value

index - 현재 element의 array index

array - 현재 element가 속한 array object

thisArg - 함수에 pass되어 그것의 "this" value로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다.

 

* value가 없는 array element에는 함수를 실행시키지 않는다.

* original array를 변경하지 않는다.

 

const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]


find()  arr.find(callback(element[, index[, array]])[, thisArg])

array의 element 중 (함수로 제공된) 테스트통과첫 번째 element리턴한다. (없으면 undefined)

더보기

리턴값: 만약 그 array의 element 중 테스트통과하는 것이 있다면 그 array element의 value를 리턴하고, 그렇지 않으면 undefined를 리턴한다.

callback - array 안의 각각의 element들에 대해서 실행될 함수

element - 현재 element의 value

index - 현재 element의 array index

array - 현재 element가 속한 array object

thisArg - 함수에 pass되어 그것의 "this" value로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다. 

 

array 안에 존재하는 각각의 element들에 대해서 함수를 한 번씩 실행시킨다.

- 만약 함수가 true value를 리턴하는 array element를 발견한다면, 그 array element의 value를 return한다. 그리고 남아있는 value들은  체크하지 않는다.

- 그렇지 않으면 undefined를 리턴한다.

 

* 빈 array에 대해서는 함수를 실행시키지 않는다.

* original array를 변경하지 않는다. 

 

var ages = [3, 10, 18, 20];

function checkAdult(age) {
  return age >= 18;
}

ages.find(checkAdult);
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12

 

findIndex() arr.findIndex(callback(element[, index[, array]])[, thisArg])

array 안의 element 중 (함수로 제공된) 테스트통과하는 첫 번째 element의 index를 r리턴한다. (없으면 -1)

더보기

리턴값: 만약 array의 element 중 테스트통과하는 것이 있다면 그 array element의 index를 리턴하고, 그렇지 않으면 -1을 리턴한다.

callback - array 안의 각각의 element들에 대해서 실행될 함수

element - 현재 element의 value

index - 현재 element의 array index

array - 현재 element가 속한 array object

thisArg - 함수에 pass되어 그것의 "this" value로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다. 

 

array 안에 존재하는 각각의 element들에 대해서 함수를 한 번씩 실행시킨다.

- 만약 함수가 true value를 리턴하는 array element를 발견한다면, 그 array element의 index를 리턴한다. 그리고 남아있는 value들은  체크하지 않는다.

- 그렇지 않으면 -1을 리턴한다.

 

* value가 없는 array element에 대해서는 함수를 실행시키지 않는다.

* original array를 변경하지 않는다. 

 

const array1 = [5, 12, 8, 130, 44];

const isLargeNumber = (element) => element > 13;

console.log(array1.findIndex(isLargeNumber));
// expected output: 3


forEach()  arr.forEach(callback(currentvalue[, index[, array]])[, thisArg])

array 안의 각각의 element에 대해서 함수를 순서대로 한 번씩 호출한다.

더보기

리턴값: undefined

callback - array 안의 각각의 element들에 대해서 실행될 함수

element - 현재 element의 value

index - 현재 element의 array index

array - 현재 element가 속한 array object

thisArg - 함수에 pass되어 그것의 "this" value로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다. 

 

* value가 없는 array element에 대해서는 함수를 실행시키지 않는다.

 

const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));

// expected output: "a"
// expected output: "b"
// expected output: "c"

 

from() arr.from(object[[, mapFunction], thisArg])

length property를 가진 또는 iterable한 object로부터 만든 Array object를 리턴한다. (string → array)

더보기

리턴값: Array object

object - array로 변환할 object

mapFunction - array의 각각의 item 들에 대해 호출할 map function

thisArg- mapFunction을 실행시킬 때, this로 사용할 value

 

var myArr = Array.from("ABCDEFG");

 

includes()  arr.includes(valueToFind[, fromIndex])

array에 specified element가 존재하는지 여부를 determine한다. (true/false)

더보기

리턴값: 불리언

valueToFind - 탐색할 element

fromIndex - 탐색을 시작할 position (디폴트: 0)

만약 그 array에 그 element가 존재한다면 true를, 그렇지 않다면 false를 리턴한다.

* 대소문자를 구분한다.

 

const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// expected output: true

console.log(pets.includes('at'));
// expected output: false

 

indexOf()  arr.indexOf(searchElement[, fromIndex])

array에 specified item이 존재하는지 앞에서부터 탐색해서, 그것의 첫 position리턴한다. (없으면 -1)

더보기

리턴값: specified item의 position을 나타내는 number, 없으면 -1

searchElement - 탐색할 element

fromIndex - 탐색을 시작할 position. 음수는 끝에서부터 몇 번째인지를 나타내고, 거기부터 시작해서 끝을 향해 탐색한다. (디폴트: the beginning)

 

만약 그 item이 한 번 이상 존재한다면, 첫 번째 출현의 position을 리턴한다.

 

const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];

console.log(beasts.indexOf('bison'));
// expected output: 1

// start from index 2
console.log(beasts.indexOf('bison', 2));
// expected output: 4

console.log(beasts.indexOf('giraffe'));
// expected output: -1

 

isArray() arr.isArray(obj)

그 object가 array인지 아닌지 determine한다.

더보기

리턴값: 불리언. 그 object가 array이면 true, 아니면 false를 리턴한다.

obj - 테스트할 object

 

var fruits = ["Banana", "Orange", "Apple", "Mango"];
Array.isArray(fruits);


join()  arr.join([separator])

array를 string으로 리턴한다.

더보기

리턴값: string. 그 array의 value들을 나타내고, specified separator에 의해서 separate된다.

 saparator - 사용할 separator. (디폴트: 콤마(,))

* original array를 변경하지 않는다.

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join(" and ");

 

keys()  arr.keys()

array의 key들을 가진 array iterator object를 리턴한다.

더보기

리턴값: array iterator object

* original array를 변경하지 않는다.

 

const array1 = ['a', 'b', 'c'];
const iterator = array1.keys();

for (const key of iterator) {
  console.log(key);
}

// expected output: 0
// expected output: 1
// expected output: 2

 

length    arr.length

array 안에 있는 element의 갯수를 리턴하거나 set한다.

더보기

리턴값: 그 array object 안에 있는 element들의 수를 나타내는 숫자

arr.length = number로 array의 길이를 바꿀 수 있다.

 

const clothing = ['shoes', 'shirts', 'socks', 'sweaters'];

console.log(clothing.length);
// expected output: 4

 

lastIndexOf()    arr.lastIndexOf(searchElement[, fromIndex])

array에서 specified item이 존재하는지 끝에서부터 탐색해서, 그것의 마지막 position리턴한다. (없으면 -1)

더보기

리턴값: specified item의 position을 나타내는 숫자. 없으면 -1

searchElement - 탐색할 item

fromIndex - 어디부터 탐색할 것인가. 음수는 끝에서부터 몇 번째인지를 나타내고, 거기서부터 시작해서 앞을 향해 탐색한다.

 

const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];

console.log(beasts.indexOf('bison'));
// expected output: 1

// start from index 2
console.log(beasts.indexOf('bison', 2));
// expected output: 4

console.log(beasts.indexOf('giraffe'));
// expected output: -1

 

map()  arr.map(callback(currentValue[, index[, array]])[, thisArg])

모든 array element에 대해서 함수를 호출하여, 그 결과로 새로운 array를 생성한다.

더보기

리턴값: original array의 각각의 element들에 대하여, 제공된 함수를 호출한 결과를 담고 있는 array

callback - array 안의 각각의 element들에 대해서 실행될 함수

currentValue - 현재 element의 value

index - 현재 element의 array index

array - 현재 element가 속한 array object

thisArg - 함수에 pass되어 그것의 "this" value로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다. 

 

array 안의 각각의 element에 대하여, 제공된 함수를 순서대로 한 번씩 호출한다.

 

const array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]


pop()  arr.pop()

array의 마지막 element를 제거하고, 그 element를 리턴한다.

더보기

리턴값: 제거된 array item을 나타내는 any type. array에 허용되는 모든 object type이 가능하다. (문자열, 숫자, 불리언 등)

 

* array의 길이를 변경한다.

* original array를 변경한다.

 

const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];

console.log(plants.pop());
// expected output: "tomato"

console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]


prototype  arr.prototype.name = value

prototype constructor는 Array() object에 새로운 property와 메소드들을 추가할 수 있게 해준다.

더보기

property를 construct할 때, 모든 array들은 디폴트로 property와 그것의 value를 부여받는다.

메소드를 construct할 때, 모든 array들은 이 메소드를 available하게 할 것이다.

 

* arr.prototype은 a single array를 나타내는 것이 아니라, Array() object 그 자체를 뜻한다.

* Prototype은 모든 JavaScript object들에 사용 가능한 global object constructor이다.

 

Array.prototype.myUcase = function() {
  for (i = 0; i < this.length; i++) {
    this[i] = this[i].toUpperCase();
  }
};

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.myUcase();

 

push()  arr.push(element1[, ...[, elementN]])

array의 끝에 새로운 item들을 추가하여, 새로운 length를 만들어서 리턴한다.

더보기

리턴값: array의 새로운 길이를 나타내는 숫자

element - array에 추가할 item

 

* array의 length를 변경한다.

* original array를 변경한다.

 

const animals = ['pigs', 'goats', 'sheep'];

const count = animals.push('cows');
console.log(count);
// expected output: 4
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]

 

reduce() arr.reduce(callback[, (previousValue, currentValue[, Index[, arr]]), initialValue])

array를 하나의 value로 reduce한다. (왼쪽 → 오른쪽)

더보기

리턴값: 콜백함수의 마지막 호출로부터의, 축적된 결과

callback - array 안의 각각의 element들에 대해서 실행될 함수

total - initialValue 또는 함수에서 바로 전에 리턴된 value

previousValue(total) - 현재 element의 value

index - 현재 element의 array index

arr - 현재 element가 속한 array object

initialValue - 함수에 pass되어 그것의 초기값으로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다. 

 

제공된 함수를 array의 각각의 value에 대해서 실행시킨다. (왼쪽에서 오른쪽으로)

함수에서 리턴된 value는 accumulator(result/total/previousValue)에 저장된다. 

 

* value가 없는 element에 대해서는 함수를 실행시키지 않는다.

* original array를 변경하지 않는다.

 

const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;

// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10

// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15

 

reduceRight()  arr.reduceRight(callback[, (previousValue, currentValue[, Index[, arr]]), initialValue])

array를 하나의 value로 reduce한다. (오른쪽 → 왼쪽)

더보기

리턴값: 콜백함수의 마지막 호출로부터의, 축적된 결과

callback - array 안의 각각의 element들에 대해서 실행될 함수

previousValue(total) - initialValue 또는 함수에서 바로 전에리턴된 value

currentValue - 현재 element의 value

index - 현재 element의 array index

arr - 현재 element가 속한 array object

initialValue - 함수에 pass되어 그것의 초기값으로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다. 

 

제공된 함수를 array의 각각의 value에 대해서 실행시킨다. (오른쪽에서 왼쪽으로)

함수에서 리턴된 value는 accumulator(result/total/previousValue)에 저장된다. 

 

* value가 없는 element에 대해서는 함수를 실행시키지 않는다.

* original array를 변경하지 않는다.

 

const array1 = [[0, 1], [2, 3], [4, 5]].reduceRight(
  (accumulator, currentValue) => accumulator.concat(currentValue)
);

console.log(array1);
// expected output: Array [4, 5, 2, 3, 0, 1]


reverse()  arr.reverse()

array 안에 있는 element들의 순서를 reverse한다.

더보기

리턴값: reverse된 array

 

* original array를 변경한다.

 

const array1 = ['one', 'two', 'three'];
console.log('array1:', array1);
// expected output: "array1:" Array ["one", "two", "three"]

array1.reverse();

console.log('array1:', array1);
// expected output: "array1:" Array ["three", "two", "one"]

 

shift()  arr.shift()

array의 첫 번째 item을 제거하고, 그 item을 리턴한다.

더보기

리턴값: 제거된 array item을 나타내는 any type. array에 허용되는 모든 object type이 가능하다. (문자열, 숫자, 불리언 등)

 

* array의 길이를 변경한다.

* original array를 변경한다.

 

const array1 = [1, 2, 3];

const firstElement = array1.shift();

console.log(array1);
// expected output: Array [2, 3]

console.log(firstElement);
// expected output: 1

 

slice()  arr.slice([begin[, end]])

array 안의 선택된 element들을, 새로운 array object로 만들어서 리턴한다.

더보기

리턴값: 선택된 element들을 가진 새로운 array

begin - 선택이 시작되는 곳을 specify하는 정수. array의 끝에서부터 세려면 음수를 사용한다. (디폴트: 0)

end - 선택이 끝나는 곳 직전을 specify하는 정수. array의 끝에서부터 세려면 음수를 사용한다. (디폴트: arr.length)

 

* original array를 변경하지 않는다.

 

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]

 

some()  arr.some(callback(currentValue[, index[, array]])[, thisArg])

array 안의 element 중 (제공된 함수의) 테스트를 통과하는 것이 있는지 여부를 체크한다.

더보기

리턴값: 불리언. array 안의 element 중 테스트를 통과하는 것이 있으면 true, 없으면 false를 리턴한다.

callback - array 안의 각각의 element들에 대해서 실행될 함수

currentValue - 현재 element의 value

index - 현재 element의 array index

array - 현재 element가 속한 array object

thisArg - 함수에 pass되어 그것의 "this" value로 사용될 value

 만약 이 parameter가 empty라면, "undefined"라는 value가 "this" value로서 pass된다. 

 

array 안에 존재하는 각각의 element들에 대해서 함수를 한 번씩 실행시킨다.

- 만약 함수가 true value를 리턴하는 array element를 발견한다면, true를 리턴한다. 그리고 남아있는 value들은  체크하지 않는다.

- 그렇지 않으면 false를 리턴한다.

 

* value가 없는 element에 대해서는 함수를 실행시키지 않는다.

* original array를 변경하지 않는다.

 

const array = [1, 2, 3, 4, 5];

// checks whether an element is even
const even = (element) => element % 2 === 0;

console.log(array.some(even));
// expected output: true


sort()  arr.sort([compareFunction])

array 안의 item들을 sort한다.

더보기

리턴값: item들이 sort된 Array object.

compareFunction - 어떠한 순서로 sort할 것인지 정의하는 함수. 이 함수는 반드시 인자들에 따라 양, 음, 0의 값 중 하나를 리턴해야 한다. (ex) a-b)

└ sort() 메소드는 두 value를 compare function에개 전달하고, 리턴된 값 (양, 음, 0)에 따라 value들을 sort한다.

 ex) 40과 100을 비교하려면, sort() 메소드는 compare function(40, 100)을 호출한다.

     함수는 40-100을 계산해서 -60(음의 값)을 리턴한다.

     sort 함수는 40을 100보다 작은 value로 sort할 것이다.

 

sort하는 순서는 알파벳 순서 또는 수의 순서일 수 있고, 오름차순 또는 내림차순일 수 있다.

이것은 string에는 잘 작동하지만, 숫자가 string으로 sort될 때, 첫째자리가 기준이 된다.

 

* original array를 변경한다.

 

const months = ['March', 'Jan', 'Feb', 'Dec'];
months.sort();
console.log(months);
// expected output: Array ["Dec", "Feb", "Jan", "March"]

const array1 = [1, 30, 4, 21, 100000];
array1.sort();
console.log(array1);
// expected output: Array [1, 100000, 21, 30, 4]

 

splice()  array.splice(start[, deleteCount[, item1[, item2[, ...]]]])

array의 item을 추가/제거하고, 추가/제거된 item을 리턴한다.

더보기

리턴값: 제거된 item들(이 존재한다면)로 만들어진 새로운 Array

start - item들을 추가/제거할 position을 specify하는 정수. 뒤에서부터 세려면 음의 정수를 사용한다.

deleteCount - 제거할 item의 수. 0으로 하면 어떤 item도 제거하지 않는다.

※ start를 설정하고 deleteCount를 설정하지 않으면, start부터 끝까지 제거한다.

item - 그 array에 추가될 새로운 item

 

* original array를 변경한다.

 

const months = ['Jan', 'March', 'April', 'June'];
months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]

 

toString()  arr.toString()

그 array의 모든 value들을 콤마로 구분한 string을 리턴한다.

더보기

리턴값: 그 array의 value들을 콤마로 구분한 string

 

* original array를 변경하지 않는다.

 

const array1 = [1, 2, 'a', '1a'];

console.log(array1.toString());
// expected output: "1,2,a,1a"


unshift()   arr.unshift([...elementN])

array의 제일 앞에 새로운 item들을 추가하고, 새로운 length를 리턴한다.

더보기

리턴값: 그 array의 새로운 length를 나타내는 숫자

element - array의 제일 앞에 추가할 item

 

* array의 length를 변경한다.

* original array를 변경한다.

 

const array1 = [1, 2, 3];

console.log(array1.unshift(4, 5));
// expected output: 5

console.log(array1);
// expected output: Array [4, 5, 1, 2, 3]

 

valueOf()  arr.valueOf()

그 array를 리턴한다.

더보기

리턴값: Array. 자기 자신을 리턴한다.

 

* original array를 변경하지 않는다.

 

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.valueOf();
// ["Banana", "Orange", "Apple", "Mango"]

 

 

 

< 출처 >

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array

 

Array

JavaScript Array 전역 객체는 배열을 생성할 때 사용하는 리스트 형태의 고수준 객체입니다.

developer.mozilla.org

https://www.w3schools.com/jsref/jsref_obj_array.asp

 

JavaScript Array Reference

JavaScript Array Reference Array Object The Array object is used to store multiple values in a single variable: Array indexes are zero-based: The first element in the array is 0, the second is 1, and so on. For a tutorial about Arrays, read our JavaScript

www.w3schools.com

 

댓글