gpt4 book ai didi

javascript - 将两个不同的关联数组放在一个关联数组中作为一个数组,在javascript中有两个关联数组

转载 作者:行者123 更新时间:2023-11-30 11:12:43 25 4
gpt4 key购买 nike

我想将两个数组连接成一个包含两个不同数组的数组第一个数组。我指的不是一个简单的数组,而是一个更复杂的数组,其字段在数组的两侧具有相同的值。

 var arr1 = [{
"id": "4",
"ip_address": "127.0.0.1",
"username": "superuser",
"password": "$2y$08$awherOdjNPRoDHAiNBGZNuA92UGfT7jsIpsMMcNnyyJMxBA8Ug9q6",
"salt": null,
"email": "super@admin.com",
"activation_code": null,
"forgotten_password_code": "NULL",
"forgotten_password_time": null,
"remember_code": "cBjcajHj8qXaNrOhkAAqPe",
"created_on": "2018-09-13",
"last_login": "1540549332",
"active": "1",
"first_name": "Super",
"last_name": "Admin",
"phone": "0",
"user_id": "4",
"groups": [{
"id": "10",
"name": "superusers",
"description": "Super Administrators",
"$$hashKey": "object:38"
}],
"$$hashKey": "object:11"
}];
var arr2 = [{
"id": "1",
"ip_address": "127.0.0.1",
"username": "administrator",
"password": "$2y$08$DoULTzDyGFyh.DTNOvxRtujA3CT2yVBMpp6joYnfUcD0FQgbm9rmy",
"salt": "",
"email": "admin@admin.com",
"activation_code": "",
"forgotten_password_code": null,
"forgotten_password_time": null,
"remember_code": "wYiqzg7AM2QbEPdVrqUhkO",
"created_on": "2010-03-18",
"last_login": "1537468397",
"active": "1",
"first_name": "Admin",
"last_name": "istrator",
"phone": "0",
"user_id": "1",
"groups": [{
"id": "3",
"name": "admins",
"description": "Administrators",
"$$hashKey": "object:32"
}],
"$$hashKey": "object:8"
}];

最佳答案

假设您将数组声明为 arr1arr2。合并它们:

var $users = arr1.concat(arr2);

如果您希望 $users 是一个包含两个元素的数组,并且每个元素都是一个数组,您可以这样做

var $users = [arr1, arr2];

但这与您想要的结果不符,没有什么意义。

关于javascript - 将两个不同的关联数组放在一个关联数组中作为一个数组,在javascript中有两个关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53006652/

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