gpt4 book ai didi

javascript - 从长对象中删除元素

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:11:03 24 4
gpt4 key购买 nike

我有一个看起来像这样的对象:

[{"1":{"name":"A","email":2}},
{"2":{"name":"B","email":3}},
{"3":{"name":"C","email":4}},]
{"4":{"name":"B","email":5}}]

我想得到如下结果:

 [{"name":"A","email":2}},
{"name":"B","email":3}},
{"name":"C","email":4}},]
{"name":"B","email":5}}]

我试过了,但这段代码不起作用,现在我有点迷失了如何为此找到解决方案。

obj.map(a => {
var newobj
a = []
a.push[a]
})

最佳答案

您需要阅读有关 Array.prototype.map() 的内容并且您使用它的方式不正确

 var homework =[{"1":{"name":"A","email":2}},
{"2":{"name":"B","email":3}},
{"3":{"name":"C","email":4}},
{"4":{"name":"B","email":5}}];

var outputofthehomework = homework.map( s => Object.values(s)[0] );
console.log(outputofthehomework)

关于javascript - 从长对象中删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49474455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com