Here's a bunch of different ways:
Using .map()
(extracts only first element of each inner array; works on all modern browsers):
const array = [[12], [33], [22], [77, 88, 99]];
const flat = array.map( x => x[0] );
console.log(flat);
Using .flatMap()
(extracts all elements of each inner array; not supported on IE or Edge as of this writing*, polyfills available):
const array = [[12], [33], [22], [77, 88, 99]];
const flat = array.flatMap( x => x );
console.log(flat);
Using .flat()
(same support limitations as above):
const array = [[12], [33], [22], [77, 88, 99]];
const flat = array.flat(1);
console.log(flat);
Using .concat()
and spread syntax (also not supported on IE / Edge*, polyfills not possible):
const array = [[12], [33], [22], [77, 88, 99]];
const flat = [].concat(...array);
console.log(flat);
Using for
...of
loop and .push()
(extracts only first element, works on every modern browser but not on IE):
const array = [[12], [33], [22], [77, 88, 99]];
const flat = [];
for (const x of array) {
flat.push( x[0] );
}
console.log(flat);
Using a plain old for(;;)
loop and .push()
(extracts only first element, works everywhere):
const array = [[12], [33], [22], [77, 88, 99]];
const flat = [];
for (let i = 0; i < array.length; i++) {
flat.push( array[i][0] );
}
console.log(flat);
Using a plain old for(;;)
loop with in-place modification (extracts only first element, modifies original array, works everywhere):
const array = [[12], [33], [22], [77, 88, 99]];
for (let i = 0; i < array.length; i++) {
array[i] = array[i][0];
}
console.log(array);
I'm sure this is not an exhaustive list.
Ps. For your example code above, you might as well extract the parent IDs directly into a flat array, like this:
const parentFolderIds = response.data.data.map( x => x.parentIds[0] );
or (if you'd like all the parent IDs for each item, in case there are several):
const parentFolderIds = response.data.data.flatMap( x => x.parentIds );
or (if you prefer an explicit loop):
const parentFolderIds = [];
for (const x of response.data.data) {
parentFolderIds.push( x.parentIds[0] );
}
or even just:
const data = response.data.data, parentFolderIds = [];
for (let i = 0; i < data.length; i++) {
parentFolderIds.push( data[i].parentIds[0] );
}
In any case, there's no point in first extracting them into a nested array and then flattening it, at least not unless you also need the nested array for something else.
*) The Edge 78.0 dev build seems to handle all of these fine, though — as one would expect, given that it's using the same JS engine as Chrome.