Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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;
    }
    
share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.