loading...

re: Use this trick to map over single objects in Javascript VIEW POST

FULL DISCUSSION
 

Wouldn't it be better to just wrap the code to be executed for each item in a method and then call the method directly if it is single item?

Say, something like

if(!Array.isArray(example)) return doSomething(example);
return example.map(doSomething);
Code of Conduct Report abuse