I have an arr
variable which looks as below:
const arr = [undefined, undefined, 'hello', 'hello', 'hi'];
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:
const arr = [undefined, undefined, 'hello', 'hello', 'hi'];
const index = arr.length;
while (index-- && !arr[index]);
console.log(arr[index]);