StackOverflow - javascript, typescript, airbnb-js-styleguide
How to perform a forEach loop on a variable defied as string | Array<string>?
if (Array.isArray(question.answer)) { (question.answer as Array).forEach(...) } also you can do this to have a uniform code let answers : Array = []; if (Array.isArray(question.answer)) { answers = [...question.answer]; } else if (!!question.answer){ answers = [question.answer]; } answers.forEach(answer => ....)
Was this helpful?
Related Articles
Have a different question?
Can't find the answer you're looking for? Submit your own question to our community.
🛎️ Get Weekly OTA Fixes
New answers, vendor issues, and updates — straight to your inbox.