Method unshift()
menambahkan satu atau lebih elemen ke indek awal array dan mengembalikan jumlah index array yang baru.
Sintaks
arr.unshift([element1[, ...[, elementN]]])
Parameter
elementN
- Elemen yang akan di tambahkan di awal array.
Returns
Properti length
baru dari objek teratas dimana method di panggil.
Deskripsi
Method unshift
menambahkan nilai yang diberikan ke awal objek array.
unshift
biasanya generic; method ini bisa berupa called atau applied ke objek menyerupai array. Objek yang tidak memiliki properti length
mencerminkan dari serangkaian urutan, properti numerik berbasis zero kemungkinan tidak berperilaku dengan cara yang berarti.
Contoh
var arr = [1, 2]; arr.unshift(0); // result of call is 3, the new array length // arr is [0, 1, 2] arr.unshift(-2, -1); // = 5 // arr is [-2, -1, 0, 1, 2] arr.unshift([-3]); // arr is [[-3], -2, -1, 0, 1, 2]
Spesifikasi
Spesifikasi | Status | Comment |
---|---|---|
ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.2. |
ECMAScript 5.1 (ECMA-262) The definition of 'Array.prototype.unshift' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype.unshift' in that specification. |
Standard | |
ECMAScript Latest Draft (ECMA-262) The definition of 'Array.prototype.unshift' in that specification. |
Draft |
Kompabilitas Browser
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 5.5 | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |