[Vuejs]-How do I replace NaN with 0 when doing division in javascript?

6👍

You don’t need to explicitly check. This should be your line 10:

interactiveLeadConversations: (((data.sent / data.interactive) || 0) * 100).toFixed(0)

What I’m doing here is to replace the expression

(data.sent / data.interactive)

with

( (data.sent / data.interactive) || 0 )

NaN evaluates to false, so if the expression (data.sent / data.interactive) equals NaN, you are offering 0 as alternative.

Leave a comment