var data = [
[
"default_PROJECT",
"Allow",
"Connect",
"Allow",
"AddComment",
"Allow",
"Write",
"Allow",
"ViewComments",
"Allow",
"ExportData",
"Allow",
"ExportImage",
"Allow",
"ViewUnderlyingData",
"Allow",
"Read",
"Allow",
"ShareView",
"Allow",
"Filter"
],
[
"Allow",
"ExportImage",
"Allow",
"Write",
"Allow",
"ViewComments",
"Allow",
"ShareView",
"Allow",
"Filter",
"Allow",
"ExportData",
"Allow",
"Connect",
"Allow",
"Read",
"Allow",
"ViewUnderlyingData",
"Allow",
"AddComment",
"Allow",
"ViewComments",
"Deny",
"ExportData",
"Allow",
"AddComment",
"Deny",
"Write",
"Allow",
"Read",
"Deny",
"ExportXml",
"Deny",
"ShareView",
"Allow",
"Connect",
"Allow",
"ChangeHierarchy",
"Allow",
"WebAuthoring",
"Deny",
"ViewUnderlyingData",
"Deny",
"Filter",
"Deny",
"ExportImage"
]
];
var newObj = {};
for(i=0; i<data.length; i++){
//newObj['name'] = data[i][0];
for(j=1; j<data[i].length;j++){
newObj[data[i][j+1]] = data[i][j];
document.write(data[i][j] + "----");
}
}
document.write(JSON.stringify(newObj));
I am attempting to create a collection of objects where each object includes the "Name" as the initial element of the array, along with the associated value which can be either "ALLOW" or "Deny". For example, I aim to achieve:
{name: "default_PROJECT", connect: "Allow", AddComment: "Allow"} ... etc
However, there are instances where duplicate keys exist in the arrays, and if the value is Deny, it will always take precedence over a previous Deny value.
I have started by iterating through each array and attempting to set the subsequent element as the key. Am I on the right path?