I am looking to remove the first two elements of an array and use both the new array and the model later in my code. My issue is that splice() is even altering my arrayModel in my code.
Here is my code
var arrayModel = ['a','b','c','d']
function dontAlterMyModel (arrayModel) {
arrayTemp = arrayModel
arrayTemp.splice(0, 2)
console.log("arrayModel", arrayModel)
console.log("arrayTemp", arrayTemp)
return
}
dontAlterMyModel(arrayModel)
Here is the result:
arrayModel [ 'c', 'd' ]
arrayTemp [ 'c', 'd' ]
Whereas I'd like to have:
arrayModel [ 'a', 'b', 'c', 'd' ]
arrayTemp [ 'c', 'd' ]
I tried to used other methods.
Using shift()
twice was also altering the model
arrayTemp = array.slice(2)
was giving me back the opposite of what I wanted: [ 'a', 'b']
How should I proceed? Thanks for your help!