I'm building an array of objects in JS, this is my structure:
$("li.user_task").each(function() {
tasks.push({
taskid: $(this).data("taskid"),
productid: $(this).data("product-id"),
productposition: $(this).data("product-position")
});
});
This is working nicely, my output on console.log():
[Object, Object, Object, Object]
0: Object
productid: 2
productposition: 1
taskid: 150
__proto__: Object
1: Object
productid: 1
productposition: 1
taskid: 151
__proto__: Object
2: Object
productid: 2
productposition: 2
taskid: 155
__proto__: Object
3: Object
productid: 1
productposition: 3
taskid: 157
__proto__: Object
length: 4
__proto__: Array[0]
I don't want my keys starting from 0 though, in this very example I'd actually like the field "taskid" to be the key for the object, how could I achieve this?