Issue
I am getting a TypeError, although my application is running properly.
"ERROR TypeError: Cannot read property 'replace' of null"
Don't get how to resolve this. Could any one give me some idea or help me to understand why this is happening?
if (isInitial) {
// Add Data Rows (initially)
for (const row of rows) {
const clientVisitGuid = row[2];
const location = row[3];
row[5] = row[5].replace(/\//g, '\/\u200B');
const service = row[5];
const rowId = `${service || 'zzz'}_${location}_${clientVisitGuid}`;
const sortString = `${service || 'zzz'}_${location}_${clientVisitGuid}`;
const daysPastDischarge = parseInt(row[6]);
const isMarked = parseInt(row[7]) === 1 ? true : false;
if (cbt.hasBodyRow(rowId) === false) {
const values: Array<[string, string | number]> = [];
let isAllClear = true;
for (let i = 0; i < row.length; i++) {
const colId: string = cbt.headerRow.headerCols[i].id;
const colVal: string | number = row[i];
if (cbt.headerRow.headerCols[i].isFlag === true && colVal !== 1) {
isAllClear = false;
}
values.push([colId, colVal]);
}
const valueHash = hash(JSON.stringify(row));
cbt.addBodyRow(
rowId,
values,
valueHash,
sortString,
daysPastDischarge,
isMarked,
isAllClear,
true,
);
}
}
}
Solution
To fix error you need to check if variable exists before trying to replace the string. Wrap it with an if statement like this:
if(row[5]) {
row[5] = row[5].replace(/\//g, '\/\u200B');
const service = row[5];
}
Answered By - Rokas Rudgalvis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.