\$\begingroup\$
\$\endgroup\$
Is there a way to make this code shorter and more succinct? Thanks
My objective is to:
- Take an array of objects (someArray)
- Use
get()
to get one specific property of each of someArr's objects (which is also an object itself, as I am working with a json object) And push this object to the 'tabs' array of the newly created object I am returning
function (someArray) { var resultObj = {}; resultObj.tabs = []; someArray.map(function (obj) { resultObj.tabs.push(obj.get()); // get() gets the dataValues (Sequelize) }); return resultObj; }
CrocodileCrocodile
1 Answer 1
\$\begingroup\$
\$\endgroup\$
Instead of pushing to an array outside of the map function, just return obj.get() in each callback and use the return value of the map call.
answered Feb 5, 2015 at 0:48
default