Skip to content
Advertisement

How to find first non null value in a typescript array?

I have an arr variable which looks as below:

JavaScript

I want to print out the first non-null value from within the arr array variable.

In above array, the output should be hello

I have written following logic but it is not giving the correct result:

JavaScript

Advertisement

Answer

Just use find:

JavaScript

It returns the value of the first element in the provided array that satisfies the provided testing function.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement