score:2

Accepted answer
var primaryArray = [1, 2, 3];

console.log('Init :');
console.log(primaryArray);

var obj = {
  array: primaryArray, // Same instance
  clonedArray: primaryArray.slice() // Clone
};

console.log(obj);

console.log('Poping from the same instance :');
obj.array.pop();

console.log(obj);
console.log(primaryArray);

console.log('Poping from the cloned array doesn\'t affect primary one :');
obj.clonedArray.pop();

console.log(obj);
console.log(primaryArray);

Related Query

More Query from same tag