1

Given the following data formats for ReleaseDate:

  1. 2014-09-23 09:00:00.923Z
  2. /Date(1407369600210)/

You can get the above information from an API with the following object dot-notation:

result.data.Items[0].ReleaseDate

However, there are cases where this particular data is undefined but how do you check if it is undefined and assign a default value/var?

Thanks in advance.

mayvn
  • 191
  • 1
  • 9

1 Answers1

1

You can simply use

if(!result.data.Items[0].ReleaseDate){ result.data.Items[0].ReleaseDate = defaultValue; }

Which will check for empty strings (""), null, undefined, false and the numbers 0 and Na

Check: How do I check for null values in JavaScript?

Community
  • 1
  • 1