convert array of object to array in javascript?

Tags: , ,



I have an array object like below:

[
    {
        first: "A",
        second: "B"
    },
    {
        first: "C",
        second: "D"
    },
]

and I want to convert to an array like this:

[
    [
        "A",
        "B"
    ],
    [
        "C",
        "D"
    ],
]

It would be highly appreciated if anyone can advise me!😊

Answer

You could map the values.

const
    data = [{ first: "A", second: "B" }, { first: "C", second: "D" }],
    result = data.map(Object.values);

console.log(result);


Source: stackoverflow