v2.5.2
Giriş yap

Javascript push() Metodu

ES1

push metodu, dizinin sonuna yeni değerler eklemek için kullanılır. İşlem sonucunda ise, dizinin yeni uzunluğunu geriye döner.

Yapısı (Syntax)array.push(item1, item2, ..., itemX)

Parametreler

  • item1, item2, ..., itemX
    ( ! ) Notice: Undefined property: stdClass::$type in /home/prototurk.com/public_html/app/view/article-js.php on line 64
    Call Stack
    #TimeMemoryFunctionLocation
    10.0001360880{main}( ).../index.php:0
    20.0035445048require( '/home/prototurk.com/public_html/app/controller/category.php' ).../index.php:101
    30.0384456608require( '/home/prototurk.com/public_html/app/view/article.php' ).../category.php:34
    40.0482536536parseTemplate( ).../article.php:112
    50.0482536648preg_replace_callback ( ).../template.php:126
    60.0482537168bb_json( ).../template.php:126
    70.0485561160require( '/home/prototurk.com/public_html/app/view/article-js.php' ).../template.php:220
    Dizinin sonuna eklenecek değerler

Dönen Değer

Dizinin yeni uzunluğunu (eleman sayısını) döndürür.

NOT
Bu metod, dizinin uzunluğunu değiştirir.
Bir dizinin başına yeni değerler eklemek için ise unshift() metodunu deneyin.

Örnekler

push() kullanım örnekleri

let sports = ['soccer', 'baseball']
let total = sports.push('football', 'swimming')

console.log(sports); // ['soccer', 'baseball', 'football', 'swimming']
console.log(total); // 4

Örneği Dene »

push() ile dizi sonuna obje ekleme örneği

const users = [
	{ name: "Tayfun Erbilen", age: 27 },
	{ name: "Mehmet Seven", age: 27 }
];

users.push({
	name: "Gökhan Kandemir",
	age: 30
})

console.log(users)

Örneği Dene »

tayfunerbilen
1352 gün önce eklendi - 4792 kez görüntülendi.
Github'da Düzenle
Önceki unshift() Sonraki find()