I am facing some trouble with loops, objects
I have json like this;
var jsonPermission = {"permissions": [
{"permissionId": 1, "permissionName": "Admin Permission", "roleDesc": "This is an Admin Permission"},
{"permissionId": 2, "permissionName": "Manager Permission", "roleDesc": "This is a Manager Permission"},
{"permissionId": 3, "permissionName": "User Permission", "roleDesc": "This is a user Permission"}
]
};
And I have to make object like this;
[
{ data: "Admin Permission", type: ["permission"] },
{ data: "Manager Permission", type: ["permission"] },
{ data: "User Permission", type: ["permission"] }
]
So I used following code;
//For Permissions
var permissions_len = jsonPermission.permissions.length;
var arr_permissions = [];
var permission_type = ["permission"];
for(var i=0;i<permissions_len;i++){
var obj_permissions = {};
obj_permissions["data"] = jsonPermission.permissions[i].permissionName;
obj_permissions["type"] = permission_type;
arr_permissions.push(obj_permissions);
}
But instead I am getting like this:
[
{ data: "Admin Permission", type: [1] },
{ data: "Manager Permission", type: [1] },
{ data: "User Permission", type: [1] }
]
How to perform?
How about:
instead of:
See the difference? You’re working with arrays.
[EDIT: actually there isn’t much difference, but this still clarifies. See comments.]