2π
β
-
You are not using
$.each()
correctly. Try this:$.each($(β[id$=β-subtotalβ]β), function (key, element) {
subtotal = some_math;
id = some_ID_Number;
data[βid-β + String(id)] = subtotal
});
- You should declare
data
as an object, not an array. An array can only have numeric keys. An object can have keys that contain other characters. If youconsole.log(data)
you will see thatdata
will contain data if itβs an object, and will be empty if initialized as an array. So try this:
var data = {};
$.each($('*'), function() {
subtotal = Math.random() * 100;
id = Math.random() * 100;
data['id-' + String(id)] = subtotal
});
console.log(data);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
π€Koen
Source:stackexchange.com