如何从arrayList中提取对象并将其添加到另一个arrayList中
我正在尝试通过修改内部对象之一将一个数组列表转换为另一个数组列表
let array1 = [
{
name: "test",
address: "testaddress",
state: {
2022: {
January: { month_state: "pending" },
},
},
},
{
name: "test2",
address: "testaddress2",
state: {
2022: {
January: { month_state: "pending" },
},
},
},
];
,我想转换成这个,这是正确的方法吗?谢谢。
let array2 = [
{
name: "test",
address: "testaddress",
2022: {
January: { month_state: "pending" },
},
},
{
name: "test2",
address: "testaddress2",
2022: {
January: { month_state: "pending" },
},
},
];
I am trying to convert one arraylist to another by modifying one of the objects inside
let array1 = [
{
name: "test",
address: "testaddress",
state: {
2022: {
January: { month_state: "pending" },
},
},
},
{
name: "test2",
address: "testaddress2",
state: {
2022: {
January: { month_state: "pending" },
},
},
},
];
And I want to convert into this, which is the correct way? Thanks.
let array2 = [
{
name: "test",
address: "testaddress",
2022: {
January: { month_state: "pending" },
},
},
{
name: "test2",
address: "testaddress2",
2022: {
January: { month_state: "pending" },
},
},
];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这段代码就可以了。
This code will do.
有多种方法可以实现您的要求。
我将向您展示使用
.map
的函数方法。您还可以使用 for 循环,这也是一种有效的方法。
There are several ways to achieve what you're asking.
I'll show you using the functional approach with
.map
You could also use a for loop, wich is also a valid approach.