Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JavaScript中从对象中删除方括号[]_Javascript_Json_Object_Split - Fatal编程技术网

如何在JavaScript中从对象中删除方括号[]

如何在JavaScript中从对象中删除方括号[],javascript,json,object,split,Javascript,Json,Object,Split,考虑以下对象 var obj1=[ { 'Charles Byers': 'Industrials', 'David Smith': 'Industrials', 'Joe Evans': 'Industrials', 'Larry Young': 'Industrials', 'Martin Hammond': 'Industrials', 'William Green': 'Industrials' }

考虑以下对象

var obj1=[
    {
      'Charles Byers': 'Industrials',
      'David Smith': 'Industrials',
      'Joe Evans': 'Industrials',
      'Larry Young': 'Industrials',
      'Martin Hammond': 'Industrials',
      'William Green': 'Industrials'
    }
  ]
我需要删除起始方括号[]和结束方括号[],而不将其转换为字符串

var obj1=
          {'Charles Byers': 'Industrials',
          'David Smith': 'Industrials',
          'Joe Evans': 'Industrials',
          'Larry Young': 'Industrials',
          'Martin Hammond': 'Industrials',
          'William Green': 'Industrials'}
       
我如何才能做到这一点?


注意:对象的大小和内容可能会更改。

您可以从单个键/值对中获取条目并映射新对象

const
对象={'Charles Byers':'Industrials','David Smith':'Industrials','Joe Evans':'Industrials','Larry Young':'Industrials','Martin Hammond':'Industrials','William Green':'Industrials',
结果=对象
.条目(对象)
.map(keyValue=>Object.fromEntries([keyValue]);

控制台日志(结果)键和值名称可能会更改。那时候我能做什么@Nina Scholzdo你有例子吗?什么在改变?请在问题中添加任何其他信息。这是格式。对象的内容可能会更改。我需要把他们分开@尼娜·斯科尔斯