js reference type of assignment

In the development, it is sometimes necessary to value other array or object to the other variables, but there are interactions between two variables, because when the value of a reference type assigned to other variables, given the fact that the storage memory address

  var ARR = [1,2,3,4,5 ]
   var of arr1 ARR =   // pass the assignment memory address space of 
  the console.log (ARR === of arr1) // to true 
  arr1.push (. 6) // when changing .arr arr1 also changes 
  the console.log (ARR) // [1,2,3,4,5,6] 
  // when the variable we need two separate noninteracting 
  var Template = the JSON.stringify (arr) 
  arr1 = JSON.parse (Template) 
  console.log (arr === arr1) // false then it will open up to arr1 separate storage space and a new arr area,
 arr1.push (7)
console.log (arr) // [1,2,3,4,5,6]
 

 

Guess you like

Origin www.cnblogs.com/cazj/p/10929195.html