-6
var array = [0, 1, 2, 3];
var numbers = [3, 6 ,2, 7];

I want to multiply each number in array with numbers without repetition of numbers from numbers

6
  • how to determine the number to be multiplied with... is there a logic Nov 24, 2015 at 3:55
  • The Array.prototype.map function will help. Nov 24, 2015 at 3:57
  • 1
    Surely you tried something first! Nov 24, 2015 at 3:57
  • random or fixed number per index is ok Nov 24, 2015 at 3:58
  • @technophobia - i can only multiply them with one number Nov 24, 2015 at 4:03

2 Answers 2

4

Fixed number for all index

var array = [0, 1, 2, 3];

array.map(
  function(n){
    return (n* number to be multiplied);
  }
);

Different number for each index

var array = [0, 1, 2, 3], numberToBeMultiplied = [1,3,5,7];

   array.map(
     function(n, i){
        return n * numberToBeMultiplied[i];
     });

You can also push the returning elements in an array.

0

Your question is not clear enough, what I get you may want to do something like this.

var array = [1,2,3,4]
var array2 = [];

for(var i = 0; i < array.length; i++) {
  var randomMultiplier = Math.floor((Math.random() * 10) + 1); //Return a random number between 1 and 10
  array2.push(array[i] * randomMultiplier);
  $('#multiplied-list').append('<li>'+array[i] * randomMultiplier+'</li>')
}
console.log(array2);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="multiplied-list"></ul>

Not the answer you're looking for? Browse other questions tagged or ask your own question.