0

Current format:

{
  "SD": {
    "Key": "SD",
    "City": "San Diego",
    "Name": "Padres"
  },
  "WSH": {
    "Key": "WSH",
    "City": "Washington",
    "Name": "Nationals"
  }
}

Expected format:

[
  {
    "Key": "SD",
    "City": "San Diego",
    "Name": "Padres"
  },
  {
    "Key": "WSH",
    "City": "Washington",
    "Name": "Nationals"
  }
]
0

2 Answers 2

3

You can do that with Object.values(...) which makes an array out of all the values from your object:

const obj = {
  "SD": {
    "Key": "SD",
    "City": "San Diego",
    "Name": "Padres"
  },
  "WSH": {
    "Key": "WSH",
    "City": "Washington",
    "Name": "Nationals"
  }
}

console.log(Object.values(obj));

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

Comments

3

It looks like Object.values is the answer, you can use it like this.

Object.values(your_object)

And it will return your expected format, here is the documentation on how it works if you would like to read further. Object.values Documentation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.