简体   繁体   English

如何在不拆分的情况下将整个对象转换为数组?

[英]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?如何将整个 obj 转换为单个数组?

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在需要时将整个 object 转换为数组? - How to convert whole object into Array when needed? 将字符串转换为数组而不拆分它 - Convert a string to an array without splitting it 如何通过拆分字符串将数组转换为 object? - How can I convert an array to an object by splitting strings? 如何在不使用分隔符(split())的情况下从字符串中获取数组,只是为了获取整个字符串并将其转换为数组类型? - How to get array from string without using dividers(split()), just to get the whole string and convert it to an array type? 如果 object 包含在 javascript 的对象数组中,如何检查整个原始 object(不使用任何属性)? - How to check with whole raw object (without using any property) if that object contains in array of objects in javascript? 如何在 javascript 中将整个数组转换为字符串 - how to convert whole array to string in javascript 在 React 中,如何获取数据并在 states 数组中渲染单个 object 而无需映射整个事物? - In React How can I fetch data and render a single object in a states array without mapping the whole thing? 如何将对象数组转换为没有索引的自定义对象 - How to convert an array of objects to a custom object without index 如何在没有依赖属性的情况下将数组转换为JavaScript中的object - How to convert an array to object in JavaScript without dependency properties 如何在不使用循环的情况下将数组转换为 Javascript 中的对象? - How to convert an array to an object in Javascript without using loops?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM