-3

I have next array:

[
        {
            "1": "somedata1"
        },
        {
            "2": "somedata2"
        },
        {
            "3": "somedata3"
        },
]

I need to convert it to [somedata1,somedata2,somedata3]. What is best way to do this?

4

2 Answers 2

1

You could take Array#flatMap with Object.values.

var data = [{ 1: "somedata1" }, { 2: "somedata2" }, { 3: "somedata3" }],
    values = data.flatMap(Object.values);

console.log(values);

Sign up to request clarification or add additional context in comments.

Comments

1

here you go.

yourArray = [..] // the stuff you put there.
yourArray.map((item, index) => item[index+1])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.