I've got a piece of code that's assuming there is a "length" to a string and then proceeds to make some calculations.
It looks like this:
txn.truncateddescription = (txn.description.length <= 40 ? txn.description : txn.description.substring(
0,37) + '...');
The error that I'm getting refers to this line and says, "Cannot read property 'length' of null(…)"
, what I'm looking basically says:
"If the 'description' field is less than or equal to 40 characters, let the 'truncateddescription' value be as it exists in the database. If not, publish it as a truncated string that consists of 37 characters plus "..."
How can I adjust it so if the system does encounter a scenario where there are not characters, it simply sets the truncateddescription value as " ?"