-1

So I have all these consts, coming from an array that i am looping through:

var characters = //list of charachters and stuff
const name = character[0]
const superpower = character[1]
const haircolor = character[2]

I am then rendering everything in a table that works perfectly, except, if a value is missing it returns undefined.

So my question is; how can I check for every value if it is undefined? And if it undefined, how can I display for that value a empty string.

For example: Current situation

...
Mario, mushroom, black
Luigi, fire flower, black
Peach, undefined, blond
Toad, undefined, undefined
...

What I want to do:

Mario Mushroom Black
Luigi Fire flower, Black
Peach Blond
Toad

the answer is probably really easy but i cant quite figure it out xd ...

usoppu
  • 5
  • 2

1 Answers1

0
console.log(value || '')

will log an empty string if value is undefined

Viktor W
  • 1,139
  • 6
  • 9