According to this article you can flatten an array using concat.
For example;
const nestedArrays: Person[][] = [
[
{firstName: "Andrew", lastName: "Smith"},
],
[
{firstName: "Chris", lastName: "Cawlins"},
],
[
{firstName: "Susan", lastName: "Sarandon"},
]
]
will can be converted to
const flattenedArray: Person[] = [
{firstName: "Andrew", lastName: "Smith"},
{firstName: "Chris", lastName: "Cawlins"},
{firstName: "Susan", lastName: "Sarandon"},
]
by using
const flattenedArray = [].concat(...nestedArrays);
I have an additional array like the follows,
const additional = ["extra1", "extra2"];
My end result should be
[
["extra1", "extra2"],
[{firstName: "Andrew", lastName: "Smith"}],
[{firstName: "Chris", lastName: "Cawlins"}],
[{firstName: "Susan", lastName: "Sarandon"}],
]
Can I achieve that using concat in typescript? Or is there another method that I would be using?
const additional = [["extra1", "extra2"]];const flattenedArray = [additional].concat(nestedArrays);const additional = [["extra1", "extra2"]];andconst flattenedArray = [additional].concat(nestedArrays);