forEach metodu (dövr) | forEach method (loop) #kody_az

Dərs haqqında

JavaScript-də forEach metodu massivlər (arrays) və ya kolleksiyalar (collections) üzərində təkrarlanmaq üçün istifadə olunan bir metoddur. forEach metodu, hər bir element üçün bir dəfə işləyən funksiyanı çağırır və bu funksiya həmin elementin dəyərini və indeksini ala bilər.

forEach metodunun xüsusiyyətləri:

1) Return dəyəri yoxdur: forEach metodu heç bir dəyər qaytarmır (undefined qaytarır). Əgər hər hansı bir dəyər qaytarmaq lazımdırsa, map, filter kimi metodları istifadə etmək lazımdır.

2) Break və continue yoxdur: forEach metodunda break və ya continue kimi təkrar dövrünü (loop) dayandırmaq və ya keçmək mümkün deyil. Əgər bu lazım olarsa, for, for...of, while kimi dövr operatorları istifadə olunmalıdır.

3) Asinxron kodlar: forEach metodu asinxron əməliyyatlar üçün nəzərdə tutulmayıb. Əgər asinxron əməliyyatlar icra edilirsə, onda for...of dövrləri daha uyğundur.

=====

The forEach method in JavaScript is used to iterate over arrays or collections, executing a provided function once for each array element. It’s a simple way to perform actions on each item in an array without the need for explicit loops like for or while.

Characteristics of forEach:

1) No return value: The forEach method does not return a value (it returns undefined). If you need to return a new array or result, you might want to use methods like map or filter.

2) No break or continue: You cannot break out of the loop or skip iterations with forEach. If you need this functionality, traditional loops like for, for...of, or while are more suitable.

3) Asynchronous operations: The forEach method is not designed for asynchronous operations. If you need to perform asynchronous tasks in a loop, consider using a for...of loop.

#kody_az #kodyaz #js #javascript #nodejs #es6 #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz

YouTube-da bax · KODY.AZ