Skip to content
Advertisement

convert array of object to array in javascript?

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!😊

Advertisement

Answer

You could map the values.

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

console.log(result);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement