Answers for "javascript how to multiply array"

1

javascript multiply array with scalar

var input = [3, 6, 4];
var scalar = 5;
var output = input.map(x => x * scalar); // [15, 30, 20]
Posted by: Guest on May-20-2020
1

multiply function javascript

// MULTIPLY FUNCTION
const multiply = (num1, num2) => {
  return num1 * num2;
};
let resulMultiply = multiply(4, 5);
console.log(resulMultiply);
// 20
Posted by: Guest on June-09-2020
-2

multiply all numbers in an array javascript

The cause is already known. Here's an alternative - using Array.reduce for your method:

console.log( [1, 2, 3].reduce( (a, b) => a * b ) );
console.log( Array.from( {length: 20} )
  .map( (v, i) => i + 1 )
  .reduce( (a,b) => a * b )
  .toLocaleString());

// for empty arrays, use some initial value
const arr = [];
if (arr.reduce( (a, b) => a * b, -1 ) === -1) {
  console.error(`The given array ${arr} is empty`);
}
Posted by: Guest on March-19-2021

Code answers related to "javascript how to multiply array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language