I want to run map()
on a variable that might either be a single object or an array. However, I can't do this if the variable is an object as that throws an error.
I tried using the spread operator to make sure the variable turns into an array but apparently that doesn't work either:
// items can either be an object or an array of objects
renderedItems = [...items]
.filter(item => !!item)
.map((item, index) => _this.renderItem(item, index));
How can I make sure the variable I'm doing a filter()
and map()
on is an array? I heard Array.isArray
isn't fully supported yet.
No comments:
Post a Comment