[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array [Back]  [Original]

Array - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

* Some parts of this feature may have varying levels of support.

Array, , .

In this article

, . JavaScript-, . , , . , , , , undefined. , ; , .

, . , , . JavaScript- (.) .

JavaScript : , 0, length 1.

js
const arr = [" ", " ", " "];
console.log(arr[0]); //  ' '
console.log(arr[1]); //  ' '
console.log(arr[arr.length - 1]); //  ' '

, , , , toString, , JavaScript:

js
console.log(arr.0); //  

. JavaScript , , ; . , , '3d', . :

js
const years = [1950, 1960, 1970, 1980, 1990, 2000, 2010];
console.log(years.0);   //  
console.log(years[0]);  //   
js
renderer.3d.setTexture(model, 'character.png');     //  
renderer['3d'].setTexture(model, 'character.png');  //   

, 3d : '3d'. ( years['2'] years[2]), . 2 years[2] JavaScript toString. '2' '02' years true:

js
console.log(years["2"] != years["02"]);

, , (!) :

js
const promise = {
  var: "text",
  array: [1, 2, 3, 4],
};

console.log(promise["array"]);

length

length . (, join, slice, indexOf ..) length . (, push, splice ..) length .

js
const fruits = [];
fruits.push("", "", "");

console.log(fruits.length); // 3

, , length:

js
fruits[5] = "";
console.log(fruits[5]); // ''
console.log(Object.keys(fruits)); // ['0', '1', '2', '5']
console.log(fruits.length); // 6

length

js
fruits.length = 10;
console.log(Object.keys(fruits)); // ['0', '1', '2', '5']
console.log(fruits.length); // 10

, length .

js
fruits.length = 2;
console.log(Object.keys(fruits)); // ['0', '1']
console.log(fruits.length); // 2

, Array.length.

JavaScript-. , . RegExp.exec, String.match String.replace. , , :

js
//     d,    
//    b,      d
//    b      d
//  

const myRe = /d(b+)(d)/i;
const myArray = myRe.exec("cdbBdbsbz");

, , :

/
input , , . cdbBdbsbz
index , ( ) , . 1
[0] , . dbBd
[1], ...[n] , , , . . [1]: bB [2]: d

Array()

Array.

Array[@@species]

Array.

Array.from()

Array .

Array.fromAsync()

Array , .

Array.isArray()

true false .

Array.of()

Array , .

Array.prototype Array.

Array.prototype.constructor

-, . Array Array.

Array.prototype[@@unscopables]

, ECMAScript ES2015 with.

Array:

length

.

Array.prototype.at()

. , .

Array.prototype.concat()

, .

Array.prototype.copyWithin()

.

Array.prototype.entries()

array iterator, / .

Array.prototype.every()

true true.

Array.prototype.fill()

.

Array.prototype.filter()

, , true.

Array.prototype.find()

, true, undefined .

Array.prototype.findIndex()

, true, -1 .

Array.prototype.findLast()

, true, undefined .

Array.prototype.findLastIndex()

, true, -1 .

Array.prototype.flat()

, .

Array.prototype.flatMap()

, , .

Array.prototype.forEach()

.

Array.prototype.includes()

true, false .

Array.prototype.indexOf()

() , .

Array.prototype.join()

.

Array.prototype.keys()

array iterator, .

Array.prototype.lastIndexOf()

() , -1 .

Array.prototype.map()

, .

Array.prototype.pop()

.

Array.prototype.push()

length .

Array.prototype.reduce()

- ( ) .

Array.prototype.reduceRight()

- ( ) .

Array.prototype.reverse()

( ) ( , ).

Array.prototype.shift()

.

Array.prototype.slice()

.

Array.prototype.some()

true true.

Array.prototype.sort()

( ) .

Array.prototype.splice()

/ .

Array.prototype.toLocaleString()

, . Object.prototype.toLocaleString().

Array.prototype.toReversed()

.

Array.prototype.toSorted()

.

Array.prototype.toSpliced()

/ .

Array.prototype.toString()

, . Object.prototype.toString().

Array.prototype.unshift()

length .

Array.prototype.values()

array iterator, .

Array.prototype.with()

.

Array.prototype[@@iterator]()

values().

:

msgArray 0, msgArray[0] msgArray[99], 100.

js
const msgArray = [];
msgArray[0] = "";
msgArray[99] = "";

if (msgArray.length === 100) {
  console.log("  100.");
}

js
const fruits = ["", ""];

console.log(fruits.length);
// 2

js
const first = fruits[0];
// 

const last = fruits[fruits.length - 1];
// 

js
fruits.forEach(function (item, index, array) {
  console.log(item, index);
});
//  0
//  1

js
const newLength = fruits.push("");
// ["", "", ""]

js
const last = fruits.pop(); //   ( )
// ["", ""];

js
const first = fruits.shift(); //   ( )
// [""];

js
const newLength = fruits.unshift(""); //   
// ["", ""];

js
fruits.push("");
// ["", "", ""]

const pos = fruits.indexOf("");
// 1

js
const removedItem = fruits.splice(pos, 1); //    

// ["", ""]

,

splice() fruits "" "" "" , .

js
const fruits = ["", "", "", ""];
const start = 1;
const deleteCount = 2;
const removedItems = fruits.splice(start, deleteCount);
console.log(fruits);
// ["", ""]
console.log(removedItems);
// ["", ""]

js
const shallowCopy = fruits.slice(); //     
// ["", ""]

:

. 'p' (6,4) (4,4). (6,4) .

js
const board = [
  ["R", "N", "B", "Q", "K", "B", "N", "R"],
  ["P", "P", "P", "P", "P", "P", "P", "P"],
  [" ", " ", " ", " ", " ", " ", " ", " "],
  [" ", " ", " ", " ", " ", " ", " ", " "],
  [" ", " ", " ", " ", " ", " ", " ", " "],
  [" ", " ", " ", " ", " ", " ", " ", " "],
  ["p", "p", "p", "p", "p", "p", "p", "p"],
  ["r", "n", "b", "q", "k", "b", "n", "r"],
];

console.log(board.join("\n") + "\n\n");

//       
board[4][4] = board[6][4];
board[6][4] = " ";
console.log(board.join("\n"));

:

R,N,B,Q,K,B,N,R
P,P,P,P,P,P,P,P
 , , , , , , ,
 , , , , , , ,
 , , , , , , ,
 , , , , , , ,
p,p,p,p,p,p,p,p
r,n,b,q,k,b,n,r

R,N,B,Q,K,B,N,R
P,P,P,P,P,P,P,P
 , , , , , , ,
 , , , , , , ,
 , , , ,p, , ,
 , , , , , , ,
p,p,p,p, ,p,p,p
r,n,b,q,k,b,n,r

Specification
ECMAScript 2027 LanguageSpecification
# sec-array-objects


Web Proxy Viewer  |  New URL  |  Original Page