如何在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你有例子吗?什么在改变?请在问题中添加任何其他信息。这是格式。对象的内容可能会更改。我需要把他们分开@尼娜·斯科尔斯