Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

a JavaScript function to multiply a set of numbers

function multiply(...myArray) {
    let result = 1;
    for (let i = 0; i < myArray.length; ++i) { 
      result *= myArray[i]; 
    }
    console.log("The product is: " + result); 
}

// For example,
// multiply(1,2,3,4);
// => 24

// The '...' is a rest operator that converts 
// any parameter in the function to an array

// Here is a shorter way of doing the same thing.
function multiply(...myArray) {
    let result = 1;
    myArray.forEach(e => {
        result *= e;
    });
    console.log("The product is: " + result); 
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: array reverse without mutating 
Javascript :: jquery check if attribute exists 
Javascript :: data binding on checkbox angular 
Javascript :: why is the radiators in cars painted black 
Javascript :: tailwind install nextjs 
Javascript :: how to get current year in nodejs 
Javascript :: firebase database check if value exists 
Javascript :: console.dir depth 
Javascript :: javascript get last character in string 
Javascript :: javascript filter array of objects by id 
Javascript :: jquery insert text into input 
Javascript :: react nginx returns 404 after reload 
Javascript :: change label value jquery 
Javascript :: jquery checked 
Javascript :: javascript get unique values from array 
Javascript :: string pop last char js 
Javascript :: neffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 
Javascript :: avaScript slice() With Negative index 
Javascript :: scrolltop top to bottom body get count 
Javascript :: loop json 
Javascript :: ckeditor change value 
Javascript :: chrome max local storage size 
Javascript :: convert json string to json object in laravel 
Javascript :: display block class javascript 
Javascript :: document ready without jquery 
Javascript :: alpinejs cdn 
Javascript :: node readFileSync json 
Javascript :: how to expand compressed js file vscode 
Javascript :: npm ERR! Missing script: "eject" react native 
Javascript :: alphabet letters in js code 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =