JakubHJ
Reactiflux4y ago
3 replies
JakubH

venus – 15-09 Dec 10

Can i write this condition in shorter version?
I want to get last index of array
arr
and if the array is emty, I want to get
0
(so basically add
-1
to
arr.length
if
arr.length
is not
0
)

const index = !!arr.length ? arr.length - 1 : 0;
Was this page helpful?