-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
  • Could you be more specific? Commented Jun 15, 2020 at 15:01
  • Can the objects have more than one property each? Commented Jun 15, 2020 at 15:01
  • 1
    Look into Object.values() and Array.map() Commented Jun 15, 2020 at 15:01
  • Get array from nested json value objects Commented Jun 15, 2020 at 15:05

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.