I run trough a couple of div's with the jQuery .each function.
With console.log I get this output
0.24 240,
0.1 100,
0.24 240,
0.24 240,
The first number on each line is a factor and the last is the sum of a multiplication
I would like to make a hash like this when the each function runs
a = {0.24: 720, 0.1: 100}
The number 0.24 as key, then sum up the the second number on each 0.24 line as value and so on.
Ideas?
Update and my solution
jQuery.fn.myFunction = function(){
var hash = {}
this.each(function(index, element) {
var key = var key = $(element).attr("data-key");
var value = $(element).attr("data-value");
if (hash.hasOwnProperty(key)){
hash[key] = hash[key] + value
}else{
hash[key] = value;
}
});
console.log(hash)
}