Answers for "w3 foreach javascript"

179

javascript foreach

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})
Posted by: Guest on April-27-2020
-1

foreach in javascript

<p>forEach() calls a function for each element in an array:</p>

<p>Multiply the value of each element with 10:</p>

<p id="demo"></p>

<script>
const numbers = [65, 44, 12, 4];
numbers.forEach(myFunction)

document.getElementById("demo").innerHTML = numbers;

function myFunction(item, index, arr) {
  arr[index] = item * 10;
}
</script>

forEach() calls a function for each element in an array:

Multiply the value of each element with 10:

650,440,120,40
Posted by: Guest on March-06-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language