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;
    }
    
\$\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.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.