Q:

Original array not getting updated when changed in referenced variable

For my work, I need to access nested object array. I do not want to access it every time with full path. So I wanted to shorten the reference by assigning the actual  reference to a variable.  
I tried to find out existing answers, but didn't get answer for this scenario.
What I have done:
Assigned the reference of array to a variable, modified the referenced value. But the original array is not getting modified.
Below is a demo code for what I want to achieve.

let obj = {
    innerObj1: {
        arr: [2,3,4,5,6]
    }
}

var ref = obj.innerObj1.arr;
console.log(ref);
// output [2,3,4,5,6]

ref = ref.filter(n => n%2 == 0);
console.log(ref);
// output [2,4,6]

//Original obj
console.log(obj.innerObj1.arr)
// output [2,3,4,5,6]

A:

This is because filter method returns a new array and you are overriding it with the new value.
As stated earlier it creates a new array, it means ref variable is not referring to old array anymore. It is referring to new array created by filter method.
You can simply use for, while or do while loop to resolve your this issue.
I hope it will help you. Please find working example here:

let obj = {
    innerObj1: {
        arr: [2,3,4,5,6]
    }
}

var ref = obj.innerObj1.arr;
console.log(ref);
// output [2,3,4,5,6]

for(let index=0; index < ref.length; index++) {
 if(ref[index] % 2 === 0) {
    ref[index] = ref[index]
  } else{
   ref.splice(index,1);
  }
}
console.log(ref);
// output [2,4,6]

//Original obj
console.log(obj.innerObj1.arr)
// output [2,3,4,5,6]

