To whom it may concern
This post is actually an example of a kind of XY Problem.
The real issue ("X") of the person asking for help is obscured, because instead of asking directly about issue X, they ask how to solve a secondary issue ("Y") which they believe will allow them to resolve issue X.
My original problem was that the array (on line 127 in the pics) was becoming empty. While I was tracing down that problem, I was shocked to find that variables were becoming empty in the middle of execution. Even though that's what this post was about, had I been thinking, I wouldn't have needed to post.
The real problem? Look at line 131 of the images...
if (siblings[childitem].my.parents.length = 0) {
The single-equal results in an empty array.
The original question follows.
I discovered this thru the chrome dev tools.
Here's the before pic.
You can see in the local scope all the relevant info, plus it's echoed in the yellow text inline with the real-time code. All the values are appropriate.
Upon executing the Next Step in the execution. . .
You can see the reticle/cursor has moved to the right in the real-time code. The previous local variables have disappeared. old parents
is now []
, and children
is undefined
.
Is it a reference problem somehow? I got the filter
syntax from this post here.
What the heck is going on?
Here's the code in text for those of you that need it.
selected.my.children.forEach (childitem => {
// let parentindex = siblings[child].my.parents.indexOf(selected.my.place);
let oldparents = siblings[childitem].my.parents;
let newparents = oldparents.filter(e => {e != selected.my.place});
siblings[childitem].my.parents = newparents;
// if (parentindex > -1) {
// siblings[child].my.parents.splice(parentindex, 1)
// }
if (siblings[childitem].my.parents.length = 0) {
siblings[childitem].faceup();
}
console.log(siblings[childitem].my);
});