What you need to do is make a Deep copy .
Unlike the Shallow copy or shallow copy (explained in prmottajr response) , you need a copy that is created without any reference to the original data, which is applicable for object arrays for example.
Solution creating a method:
(method that will create a new object and will copy the properties for that object)
var a=[{nome:"oi"},{nome:"xau"}]
var b = Clonar(a);
b[0].nome=5;
console.log(a, b);
function Clonar(source) {
if (Object.prototype.toString.call(source) === '[object Array]') {
var clone = [];
for (var i=0; i<source.length; i++) {
clone[i] = Clonar(source[i]);
}
return clone;
} else if (typeof(source)=="object") {
var clone = {};
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
clone[prop] = Clonar(source[prop]);
}
}
return clone;
} else {
return source;
}
}
Solution with Jquery :
var a=[{nome:"oi"},{nome:"xau"}]
var b = jQuery.extend(true, {}, a);
b[0].nome=5;
console.log(a, b);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Asalreadymentionedinotheranswers.Solutionserializinganddeserializing:
let a=[{nome:"oi"},{nome:"xau"}]
let b=JSON.parse(JSON.stringify(a))
b[0].nome=5
console.log(a,b)