2
\$\begingroup\$

Is there a way to make this code shorter and more succinct? Thanks

My objective is to:

  1. Take an array of objects (someArray)
  2. 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)
  3. 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;
    }
    
asked Feb 5, 2015 at 0:17
\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

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
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.