Currently, I have an array and object containing items, and my goal is to check each item in the array to see if its path matches any of the object names. If a match is found, I push it into that object's array.
While this part is working fine, I am struggling with what to do when no match is found. In such cases, I want to create a new item based on the name of the array item and push it inside the object.
All my attempts so far have resulted in duplicated values, and I believe I need a third object or array, but I can't seem to figure it out.
Let me provide a clearer explanation:
cList = {
"rList": {
"Significant": [
{
"Path": "Significant\\Significant Charts",
"Name": "Charts"
}
]
},
};
and
SSList = {
value: [
{
"Name": "Test long name",
"Path": "/someFolder/Test long name",
},
{
"Name": "Untitled",
"Path": "/Significant/Untitled",
}
]
};
Here is my current code snippet:
for (var cFolder in this.cList.rList) {
this.SSList.forEach((ssFile)=> {
if(ssFile.Path.indexOf(cFolder) >= 0){
this.cList.rList[cFolder].push(ssFile);
}
});
}
The first item in SSList will not be pushed since it doesn't match any existing objects. My intention is to create a new array and push it inside rList.
var folderName = ssFile.Path.split("/");
this.cList.rList[folderName[1]].push(ssFile);