gpt4 book ai didi

javascript - 如何使用 angularjs 或简单的 javascript 合并两个对象?

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

我有两个对象

$scope.a= {"Sedan":{"Audi":["A3","A4"]},"Hatchback":{"Maruthi":["Swift"]}}; 
var b= {"Hatchback":{"Volkswagen":["Polo"],"Fiat":["Punto1"]}};

合并后需要如下结果

{"Sedan":{"Audi":["A3","A4"]},"Hatchback":{"Maruthi":["Swift"],"Volkswagen":["Polo"],"Fiat":["Punto1"]}};

最佳答案

你可以这样做..

$scope.a= {"Sedan":{"Audi":["A3","A4"]},"Hatchback":{"Maruthi":["Swift"]}}; 
var b= {"Hatchback":{"Volkswagen":["Polo"],"Fiat":["Punto1"]}};

var mergedobj= angular.merge($scope.a, b); //merge object b into $scope.a

在这里查看工作plunkr http://plnkr.co/edit/VpHwERUmLqx6MlwQj6JB?p=preview

关于javascript - 如何使用 angularjs 或简单的 javascript 合并两个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33430176/

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