I have created an array named allchildsAr and I am populating it with objects that contain a parent property (an object) and a chlds property which is an Array.
Here is the code to fill the array :
Ti.API.info("*****allchildsAr["+level+"] is null and "+elmn+" children will be added to it ");
allchildsAr[level] = new Array({parent:elmn,chlds:elmn.getChildren()});
After adding elements to the array, I attempt to display its contents:
Ti.API.info("*****allchildsAr["+level+"] after add");
allchildsAr[level].forEach(logArrayJsonElements);
The logArrayJsonElements method looks like this:
function logArrayElements(elemnt, indx, array) {
Ti.API.info("*****Element at [" + indx + "] : " + elemnt.id);
}
function logArrayJsonElements(elemnt, indx, array) {
Ti.API.info("*****Element at [" + indx + "] : " + elemnt.parent.id);
elemnt.chlds.forEach(logArrayElements);
}
While this setup is effective, I now want to pass the parent element through logArrayElements so I can display it as the parent of the array's displayed element (and perform other operations later on). This has led me to modify the logArrayElements function as follows:
function logArrayElements(elemnt, indx, array, parent) {
Ti.API.info("*****Element at [" + indx + "] : " + elemnt.id+" child of :"+parent);
}
However, I am facing confusion as when logArrayElements is called within forEach, arguments are not explicitly passed. If I include the parent parameter as intended, it gets confused with another parameter (usually the element parameter). How do I get the parent inside the function and ensure forEach passes it along with other parameters?