I have implemented a script to eliminate JSON objects from an array that exist in both the array itself and another JSON object:
var stageChildren = stage.sprites;
for (var i = 0; i < stageChildren.length; i++) {
for (var x in mainMenu) {
if (mainMenu[x] === stageChildren[i]) {
console.log(x);
}
}
}
To clarify, let's consider two objects named: object1
& object2
.
In object1
, there may be a common JSON object present in object2
as well. In such cases, the object is removed from object1
.
Although this script functions correctly, I suspect it could significantly impact performance. Why? Because there are approximately 50 distinct objects within stageChildren
, and 10 inside mainMenu
. The script iterates through each object in stageChildren
, checks if that object also exists within mainMenu
(through another for
loop), and proceeds to the next 49 objects.
Is there a more efficient method to achieve this?