Flattening a 2D array to use map/reduce
New

This code can actually be further reduced by using JavaScript's apply:

y = y.concat.apply(y, cats);


The above line will merge all the arrays inside the cats array into a single array and then copy it into y.

This is better than the solution you already have because:


It is faster. No more looping over two arrays.
It is easier to read. If you want, just slap a comment on this line and it is very easy to understand.




Old


it.forEach(function(it){
    y.push(it);
});



This section is over-done. All you are doing is copying the array it into y, and JavaScript already has a built in function for that: Array.prototype.concat.

You can use this function to copy one array into another.

Now, your code becomes this:

var x = cats.forEach(function(it) {
    y = y.concat(it);
});