Javascript every() Metodu
ES5
Dizideki tüm öğelerin belirtilen koşula uygun olup olmadığını test eder. Testi geçemeyen ilk öğede metod geriye false
döndürür ve işlemi durdurur. Eğer tüm öğeler testi geçerse geriye true
döner.
Parametreler
-
currentValue
( ! ) Notice: Undefined property: stdClass::$type in /home/prototurk.com/public_html/app/view/article-js.php on line 64 Call Stack # Time Memory Function Location 1 0.0005 363136 {main}( ) .../index.php:0 2 0.0047 447304 require( '/home/prototurk.com/public_html/app/controller/category.php' ) .../index.php:101 3 0.0077 458928 require( '/home/prototurk.com/public_html/app/view/article.php' ) .../category.php:34 4 0.0162 538920 parseTemplate( ) .../article.php:112 5 0.0163 539032 preg_replace_callback ( ) .../template.php:126 6 0.0163 539552 bb_json( ) .../template.php:126 7 0.0165 569120 require( '/home/prototurk.com/public_html/app/view/article-js.php' ) .../template.php:220 Test edilen elemanın değeri -
index
( ! ) Notice: Undefined property: stdClass::$type in /home/prototurk.com/public_html/app/view/article-js.php on line 64 Call Stack # Time Memory Function Location 1 0.0005 363136 {main}( ) .../index.php:0 2 0.0047 447304 require( '/home/prototurk.com/public_html/app/controller/category.php' ) .../index.php:101 3 0.0077 458928 require( '/home/prototurk.com/public_html/app/view/article.php' ) .../category.php:34 4 0.0162 538920 parseTemplate( ) .../article.php:112 5 0.0163 539032 preg_replace_callback ( ) .../template.php:126 6 0.0163 539552 bb_json( ) .../template.php:126 7 0.0165 569120 require( '/home/prototurk.com/public_html/app/view/article-js.php' ) .../template.php:220 Test edilen elemanın indis değeri -
arr
( ! ) Notice: Undefined property: stdClass::$type in /home/prototurk.com/public_html/app/view/article-js.php on line 64 Call Stack # Time Memory Function Location 1 0.0005 363136 {main}( ) .../index.php:0 2 0.0047 447304 require( '/home/prototurk.com/public_html/app/controller/category.php' ) .../index.php:101 3 0.0077 458928 require( '/home/prototurk.com/public_html/app/view/article.php' ) .../category.php:34 4 0.0162 538920 parseTemplate( ) .../article.php:112 5 0.0163 539032 preg_replace_callback ( ) .../template.php:126 6 0.0163 539552 bb_json( ) .../template.php:126 7 0.0165 569120 require( '/home/prototurk.com/public_html/app/view/article-js.php' ) .../template.php:220 Test edilen elemanın ait olduğu dizi objesi
Dönen Değer
Dizideki tüm öğeler testi geçerse true
, aksi halde false
döner.
Örnekler
Tüm öğelerin değerini test etme
Aşağıdaki kod, dizideki tüm öğelerin 10'dan büyük olup olmadığını test eder.
Arrow fonksiyonlarla kullanımı
Arrow fonksiyonları aynı işlemin daha kısa yazılmasını sağlar.
Objeleri test etmek
Metod parametre olarak sadece dizi değil bir değerde alabilir. Aşağıdaki kod, bir değer ve dizilerin birleşimini gösterir.
Diğer parametrelerine bir örnek
Aşağıdaki kod, 2. ve 3. parametrelerinin kullanımını gösteren bir örnektir.
Öğelerin değiştirilmesi
Eğer test sırasında diziyi güncellerseniz, yeni bir öğe eklerseniz ya da bir öğeyi silerseniz nasıl işleyeceğine dair bir örnek.