آموزش مقدماتی جاوا اسکریپت2024|forEach()| قسمت 32

تعداد بازدید : 10 | تاریخ انتشار : 12 اردیبهشت 1403 10:21 | مدت زمان : 00:08:01 | دسته بندی : فناوری و رایانه

00:00:00 مقدمه 00:00:18 مثال 1 00:03:58 مثال 2 00:07:37 نتیجه گیری // forEach() = method used to iterate over the elements // of an array and apply a specified function (callback) // to each element // array.forEach(callback) // element, index, array are provided // ------------- EXAMPLE 1 ------------- const numbers = [1, 2, 3, 4, 5]; numbers.forEach(cube); numbers.forEach(display); function double(element, index, array){ array[index] = element * 2; } function triple(element, index, array){ array[index] = element * 3; } function square(element, index, array){ array[index] = Math.pow(element, 2); } function cube(element, index, array){ array[index] = Math.pow(element, 3); } function display(element){ console.log(element); } // ------------- EXAMPLE 2 ------------- let fruits = ["apple", "orange", "banana", "coconut"]; fruits.forEach(capitalize); fruits.forEach(display); function upperCase(element, index, array){ array[index] = element.toUpperCase(); } function lowercase(element, index, array){ array[index] = element.toLowerCase(); } function capitalize(element, index, array){ array[index] = element.charAt(0).toUpperCase() + element.slice(1); } /* function display(element){ console.log(element); } */

javascript,جاوا اسکریپت,آموزش javascript,فیلم آموزش javascript