Partitioning an array of objects into four arrays by one attribute I have an array of API objects, below is an example of one object:

{
    description: "Get a list of most recent social alerts"
    example_input: ""
    example_output: "status"
    id: 19
    method: "GET"
    resource: "/api/alerts"
}


With my code below, I'm able to loop through the big Array, then filter out items into 1 of 4 arrays (for GET, POST, PUT and DELETE)

RestFactory.getREST().then(function(res) {
    filterArrays(res.data.rest_methods);
});

function filterArrays(data) {
    for (var i=0; i&lt;data.length; i++) {
        if (data[i].method === 'GET') {
            getArray.push(data[i]);
        }
        else if (data[i].method === 'POST') {
            postArray.push(data[i]);
        }
        else if (data[i].method === 'PUT') {
            putArray.push(data[i]);
        }
        else if (data[i].method === 'DELETE') {
            deleteArray.push(data[i]);
        }
    }
}


I feel that this is not the most efficient way to accomplish this, how should this be refactored? Would you recommend lodash in this scenario?
This can easily be done with array.reduce

let resultsByMethod = data.reduce((results, result) =&gt; {
  if(!results[result.method]) results[result.method] = [];
  results[result.method].push(result);
  return results;
}, {});


The end result is something like:

{
  GET: [...],
  POST: [...],
  PUT: [...],
  DELETE: [...]
}


One disadvantage in your approach is when it encounters a method that's note one of the 4 you're comparing.