JavaScript

How To Copy An Array In Javascript

By Niall Kader1 min read

Here's one that doesn't come up all that often, although it seems like it should. How to grab a copy of an array (by value). It's actually super simple, just use the slice() methid.

var someArray = ['a', 'b', 'c'];
var copyArray = someArray.slice();