Vikash21 says:
Error:Uncaught TypeError: Cannot read property 'split' of undefined
Put debugger in function and check the value of arrayList to make change accordingly.
// Calculate total from other array object value
function CalculateTotal(arrayList) {
//put debugger to check the arrayList value
debugger
var total = 0;
for (var i = 0; i < arrayList.split(',').length; i++) {
if (!isNaN(arrayList.split(',')[i].trim()) && parseFloat(arrayList.split(',')[i].trim()) > 0) {
total += parseFloat(arrayList.split(',')[i]);
}
}
return total.toString();
}
also if you dont want to make name as short name then just set shortname as.
// You can change the variable value as it is not to use Getshortname function.
shortname = clients[i];
// or you can change like below
if (!hashOfArr[clients[i]]) {
hashOfArr[clients[i]] = [];
}
hashOfArr[clients[i]].push(total);
As Demo given by below array values.
you must sure your data is coming like in this format if not then debug it and try to modify your code as it causing error to splitting values as it’s not in proper format so you need to handle it.
kalpesh says:
var clients = ["ABC Medical Centre", "Atlantic Foot & Ankle Specialists", "Billing Bridge", "Transcription star", "The Billing Bridge"];
var pending1 = ["2", "0", "10, 14, 0, 0, 0, 0", "5", "1"];
If your both array values come like below
var clients = ["ABC Medical Centre", "Atlantic Foot & Ankle Specialists", "Billing Bridge", "Transcription star", "The Billing Bridge"];
var pending1 = ["[2]", "[0]", "(6) [10, 14, 0, 0, 0, 0]", "[5]", "[1]"];
then just modify the function as
// Calculate total from other array object value
function CalculateTotal(arrayList) {
var total = 0;
var values = null;
if (arrayList.indexOf('[') != "-1" && arrayList.indexOf(']') != "-1") {
values = arrayList.substring(arrayList.indexOf('[') + 1, arrayList.indexOf(']')).split(',');
} else {
values = arrayList.split(',');
}
for (var i = 0; i < values.length; i++) {
if (!isNaN(values[i].trim()) && parseFloat(values[i].trim()) > 0) {
total += parseFloat(values[i]);
}
}
return total.toString();
}
it will work for both the values for pending1 array if its like below
var pending1 = ["2", "0", "10, 14, 0, 0, 0, 0", "5", "1"];
// or
var pending1 = ["[2]", "[0]", "(6) [10, 14, 0, 0, 0, 0]", "[5]", "[1]"];
You must sure what kind of values getting from pending1 array so according to that you need to modify the function. So just debug it find the array values and change accordingly to handel in function as if you need to calculate something from any object then you must sure the correct format to be passed for the object.