حلقه forEach در جاوا اسکریپت روی یک آرایه یا لیست انجام میشود و به عنوان آرگومان ورودی یک function دریافت میکند
var fruits = ["apple", "orange", "cherry"]; fruits.forEach(myFunction); function myFunction(item, index) { document.getElementById("demo").innerHTML += index + ":" + item + ""; } output : 0:apple
1:orange
2:cherry
array.forEach(function(currentValue, index, arr), thisValue)
var numbers = [65, 44, 12, 4]; numbers.forEach(myFunction) function myFunction(item, index, arr) { arr[index] = item * 10; } document.getElementById("demo").innerHTML = numbers; output : 650,440,120,40
var numbers = [65, 44, 12, 4]; var newarray = numbers.map(myFunction) function myFunction(num) { return num * 10; } document.getElementById("demo").innerHTML = newarray;
تا کنون نظری داده نشده است .
اولین کسی باشید که دیدگاه خود را ثبت می کند .
لطفا منتظر بمانید...