简体   繁体   中英

How to convert the whole object into Array without splitting?

My array:

{
  "address": "Baripada",
  "prime": "true",
  "time": "1290"
}

I need to change this into

[
  {
    "address": "Baripada",
    "prime": "true",
    "time": "1290"
  }
]

I tried this:

Object.entries(obj)

The output am getting is like

[
  [
    "address",
    "Baripada",
  ],
  [
    "prime",
    "true",
  ],
  [
    "prime",
    "1290",
  ]
]

How to get as a convert whole obj into single array?

In simple ways, if you have such an object, wrap it in [] .

 const obj = { "address": "Baripada", "prime": "true", "time": "1290" }; const arr = [obj]; console.log(arr);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM