Combining arbitrary number of lists inside json I have some JSON where each key stores an array, and I need to combine all those arrays into a single array.  My current solution doesn't seem the most friendly to review, but without forEach not able to return a value i'm struggling for a succinct solution.

config = {"levels": {"first": ["a", "b", "c"], "second": ["d", "e", "f"]}};

let combine = [];
Object.keys(config["levels"]).forEach(key=&gt;combine.push(config["levels"][key]));
let levels = [].concat.apply([], combine);
// levels == ["a", "b", "c", "d", "e", "f"]


I never know how children config["levels"] will have there will be so this needs to be dynamic.
First

but without forEach not able to return a value i'm struggling for a succinct solution.

Addressing this in your post, in the future it may help to know you can use the .map() function, which does return values to an array, unlike forEach()
an example using .map() and what you have:


const config = {"levels": {"first": ["a", "b", "c"], "second": ["d", "e", "f"]}};
const accessor = config.levels

let combine = Object.keys(accessor).map(key=&gt;{return accessor[key]});
let levels = [].concat.apply([], combine);

console.log(levels);
// levels == ["a", "b", "c", "d", "e", "f"]



More Succinct Solution
That said, something like this may be what you're looking for:


const config = {"levels": {"first": ["a", "b", "c"], "second": ["d", "e", "f"]}};
const accessor = config.levels

const combine = Array.prototype.concat(...Object.values(accessor));
console.log(combine)



NOTE 1: Accessor is pulled out in case it needs to change, but is not necessary