JavaScript Dizisi itme()
Örnekler
Bir diziye yeni bir öğe ekleyin:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Diziye iki yeni öğe ekleyin:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon");
Tanım ve Kullanım
Yöntem , bir dizinin sonunapush()
yeni öğeler ekler .
Yöntem push()
, dizinin uzunluğunu değiştirir.
Yöntem push()
yeni uzunluğu döndürür.
Sözdizimi
array.push(item1, item2, ..., itemX)
parametreler
Parameters | Description |
item1 item2 .. itemX |
The item(s) to add to the array. Minimum one item is required. |
Geri dönüş değeri
Tip | Açıklama |
Bir sayı | Dizinin yeni uzunluğu. |
Tarayıcı Desteği
push
bir ECMAScript1 (ES1) özelliğidir.
ES1 (JavaScript 1997) tüm tarayıcılarda tam olarak desteklenir:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Daha fazla örnek
Diziye 3 öğe ekleyin:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon", "Pineapple");
push()
yeni uzunluğu döndürür:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");