如何在javascript中将对象添加到数组[重复]

时间:2021-10-16 07:34:56

This question already has an answer here:

这个问题在这里已有答案:

I have this code like this:

我有这样的代码:

$scope.role.object_access_right = {contact:1,group:1,image:1,text:1,email_template:1,email:1,channel:1,campaign:1,invoice:1,user:1,account:1,tenant:1,}

I have empty array here,

我这里有空数组,

$scope.access = [];

How can I push the key to empty array to have result ?

如何将键推到空数组才能得到结果?

 $scope.access = [contact,group,text ...]

1 个解决方案

#1


6  

$scope.access = Object.keys($scope.role.object_access_right);

That should do the trick.

这应该够了吧。

#1


6  

$scope.access = Object.keys($scope.role.object_access_right);

That should do the trick.

这应该够了吧。