JSFiddle - React, Tailwind, and code Playground

by jfriend00

HTML

<script src="https://dl.dropboxusercontent.com/u/7909102/log.js"></script>

JavaScript

function cloneArray(arr) {  
  // Deep copy arrays. Going one level deep seems to be enough.
  var clone = [];
  for (i=0; i<arr.length; i++) {
    clone.push( arr[i].slice(0) )
  }
  return clone;
}

var x = [[{foo: 1}]];

var y = cloneArray(x);
x[0][0].foo = 2;

// now see what the value is in `y`
// if it's 2, then it's been changed and is not a true copy
// both arrays have a reference to the same object
log(y[0][0].foo);