jQuery Data Type How to - Deep clone array








Question

We would like to know how to deep clone array.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-compat-git.js'></script>
<!--from  w  ww.j  a va 2  s . c  o  m-->
<script type='text/javascript'>

var numbs = $.extend(true, {}, [1,2,3]);
for (var numb in numbs){
    document.writeln(numbs[numb]);
}

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: