-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 ...

0

1 Answer 1

0
console.log(value || '')

will log an empty string if value is undefined

Sign up to request clarification or add additional context in comments.

1 Comment

Oh wow that is pretty cool, Thanks for the help!!!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.