pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift

ref="https://developer.mozilla.org/favicon.ico" />

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.prototype.unshift()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..

Сводка

Метод unshift() добавляет один или более элементов в начало массива и возвращает новую длину массива.

Синтаксис

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

Параметры

element1, ..., elementN

Элементы, добавляемые в начало массива.

Возвращаемое значение

Новое свойство length объекта, над которым был вызван метод unshift.

Описание

Метод unshift вставляет переданные значения в начало массивоподобного объекта.

Метод unshift не является привязанным к типу; этот метод может быть вызван или применён к объектам, напоминающим массив. Объекты, не содержащие свойство length, отражающее последний элемент в серии последовательных числовых, начинающихся с нуля, свойств, могут повести себя неправильным образом.

Примеры

js
var arr = [1, 2];

arr.unshift(0); // результат вызова равен 3, новой длине массива
// arr равен [0, 1, 2]

arr.unshift(-2, -1); // = 5
// arr равен [-2, -1, 0, 1, 2]

arr.unshift([-3]);
// arr равен[[-3], -2, -1, 0, 1, 2]

Спецификации

Specification
ECMAScript® 2026 Language Specification
# sec-array.prototype.unshift

Совместимость с браузерами

Смотрите также

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy