I've tried replicating your issue and these are my results:
var oldArray = ['a','b','c','d'];
var newArray = [];
var obj = oldArray[0]; // store the first value in a new variable
newArray[0] = obj; // push the variable's value to the first index of the new array
console.log(obj);
// 'a'
console.log(newArray);
// ['a']
console.log(newArray[0]);
// 'a' (the same as obj)
console.log(oldArray);
// ["a", "b", "c", "d"]
console.log(oldArray[0]);
// 'a'
Based on the scope of the script and the data in oldArray
, these is correct behaviour. Either your test case isn't reduced properly or the problem isn't reflected by your question.
Since I was testing with strings and not objects, there may be some differing behaviour in your specific use case, but giving some sample data about the contents of oldArray
would greatly help your cause.