I'm trying to keep the base value of something but will still not keep its value even if its a const and param? I dont know how it does that but heres my code.
function load_descendants(elem,array,mooo)
{
const origin = mooo
for (var c=0;c<array[0].length;c++)
{
//NOTE WHILE EDITING ON STACK OVERFLOW: the variable "mooo" from each loop some reason gets changed and keeps its value and kind of breaks the rules of javascript somehow
var mew = origin
console.log(origin,mew,c)
if (c!=0) {
mew.splice(mew.length-2,2) // had to add in because the param mooo wouldnt keep its value since its supposed to do that?
}
mew.push("["+0+"]")
mew.push("["+c+"]")
var ob = new_child_object(array[0][c][1],array[0][c][2],mew)
if (ob != false)
{
elem.appendChild(ob[0])
if (array[0][c][0].length != 0) {
load_descendants(ob[1],array[0][c],ob[2])
}
}
}
}
function loadExplorer()
{
document.getElementById("main").innerHTML = ""
Object.entries(GAME).forEach(([k,v]) => {
var ob = new_object(v[1],v[2],[v[1]])
document.getElementById("main").appendChild(ob[0])
load_descendants(ob[1],v,[k])
update_width()
})
}
loadExplorer()
I've tried to stop the values from changing but all it does is keep the last values from the for loop and give the same values it changed to the next index loop I even checked every variable if it had the same name and changed the index variables but there isn't any change. Please if you have an answer I would appreciate it.
After 5 hours I've got it. I just needed to get a deep copy of the variable. Thanks also. Heres the link if anyone is on this problem also Copy a variable's value into another