I would say this is a partial solution, as objects {b:2} and {c:3} are still pointing to the same reference. Another issue with the solution is that it will affect the bindings, if you are using any JS framework to display data.

Try the below solution:

function addToArray(arrayRef,value){
var newArray = arrayRef.map(val=>{
return Object.assign({},val)
});
newArray.push(value);
newArray[0].a = 10;
console.log(newArray);
}

Here we will be creating new references for each object.

A UI /UX Designer and JS Enthusiast, with a passion for travelling and writing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store