I want to create dynamic array of taxes in javascript for which I used the following code:
$("table").on("focusout",".tax_amount",function(e){
var IDs = new Array();
$('.tax_amount').each(function(){
k = this.id;
if(typeof IDs[k] === 'undefined') {
IDs[k] = parseFloat(this.value);
}else{
IDs[k]+= parseFloat(this.value);
}
});
console.log(IDs);
});
Now I want to iterate that IDs array to create the table. But .length & .size() are not working on IDs array. When I see the result of array in console it shows following
Unable to get how to use that array for $.each.
I have solved it using following code:
var IDs = {}
$('.tax_amount').each(function(){
k = this.id;
if(k in IDs) {
IDs[k]+= parseFloat(this.value);
}else{
IDs[k] = parseFloat(this.value);
}
});
console.log(IDs.length);
$.each(IDs,function(key,index){
console.log(key);
console.log(index);
});
Thanks a lot Quentin for guiding in the right direction.
