After calling an ajax service, I received a collection of objects where Object (A) properties are Group, order, salary. For example, the objects could be
[Employee, 1, 1500],[Management, 2, 2000], [Employee, 3, salary]
.
My task is to create an array for each group that can store different objects (B), with a format like [OrderNo, String]
, which will also be fetched through an ajax call. I need to avoid making redundant ajax calls for groups whose arrays have already been created.
The challenge is that the number of objects (A) or (B) is unknown in advance and I need to reference the (A) object arrays for iteration.
Pseudo code representation of the result
var groups = [
Employee: [[1372, "Free meals"],[947, "Lower salary"],[21, "Overtimes"],[74667,"Great Xmass party"]],
Management: [[11, "Responsibility"],[485,"Extra meetings"]]
]
I'm unsure how to correctly implement the following logic:
for(var index in "Object A"){
if(groups.AlreadyContains("Object A[index]")){
do nothing;
}
else {
var "Object A[index]" = MyAjaxCall("Object A[index]");
groups.AddAnArray("Object A[index]");
}
}
function MyAjaxCall(par){ call ajax and return collection of B objects;}
foreach(var i in groups.Management)
{Console.log(Management[i].PropertyName);}
Console output: Responsibility, Extra meetings