0

I have two arrays:

Ex: count["1","3","1"..........], amount["10","20","30"..........]

I need to perform multiplication & addition as:

var total = (1x10)+(2x20)+(1x30)...........

Can anyone help. Thanks

2 Answers 2

2

You can use this code

var count = [1, 3, 1];
var amount = [10, 20, 30];
var sum = 0;
for (var i = 0; i < count.length; i++) {
  sum += count[i] * amount[i];
}
console.log(sum)

Sign up to request clarification or add additional context in comments.

Comments

0

var a = ["1","3","1"], b = ["10","20","30"], sum = 0;
$.each(a, function(k,v){
	sum += (parseInt(v) * parseInt(b[k]));
})
console.log(sum); // 100
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

100

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.