Multiply all the values in array with a specific number: - Javascript Array

Javascript examples for Array:forEach

Description

Multiply all the values in array with a specific number:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>


<p>Multiply with: <input type="number" id="multiplyWith" value="10"></p>
<button onclick="numbers.forEach(myFunction)">Test</button>

<p>Updated array: <span id="demo"></span></p>

<script>
var numbers = [6, 44, 12, 4];/*from   w  w w.j  av a  2 s.  co  m*/

function myFunction(item,index,arr) {
    arr[index] = item * document.getElementById("multiplyWith").value;
    demo.innerHTML = numbers;
}
</script>

</body>
</html>

Related Tutorials