在一个对象上设置两个键

Set Two Keys on an Object

本文关键字:两个 一个对象 设置      更新时间:2023-09-26

我有一个对象$scope.int.views,我想设置两个新对象,一个彼此,如下所示:

$scope.int.views[key][$scope.data.year] = {};

但这不起作用,因为$scope.int.views[key] 是未定义的。我知道如何做到这一点的最好方法是:

$scope.int.views[key] = {}, $scope.int.views[key][$scope.data.year] = {};

有没有更简单的方法可以做到这一点?

像这样

($scope.int.views[key] = {})[$scope.data.year] = {};