About 193,000 results
Open links in new tab
  1. Fastest way to duplicate an array in JavaScript - Stack Overflow

    Oct 20, 2010 · To make an independent copy of an array rather than a copy of the refence to it, you can use the array slice method. Example: var oldArray = ["mip", "map", "mop"]; var …

  2. How to clone an array in JavaScript - freeCodeCamp.org

    Apr 11, 2019 · slice returns a shallow copy of an array based on the provided start/end index you provide. If we want the first 3 elements: [ 1 , 2 , 3 , 4 , 5 ].slice( 0 , 3 ); // [1, 2, 3] // Starts at …

  3. How to clone an array in JavaScript - GeeksforGeeks

    Nov 9, 2024 · In JavaScript, cloning an array means creating a new array with the same elements as the original array without modifying the original array. Here are some common use cases …

  4. How to copy/clone an Array in JavaScript - Medium

    Aug 11, 2023 · There are several ways to copy or clone an array in JavaScript. Here are some common methods with examples. 1. Shallow Copy Methods. The spread operator (`…`) …

  5. Create shallow and deep copy of an array in JavaScript

    Oct 2, 2023 · We can use this function to copy an array by passing an empty array as the target object and the original array as the source object. We can also pass a true value as the first …

  6. How to copy/clone arrays in javascript - DEV Community

    Feb 7, 2023 · We simply loop over the original array and push each element to the new array. newArr.push(arr[i]); The spread operator is one of the fastest methods and was introduced …

  7. 5 Ways To Clone an Array in Javascript - Zaid's bits

    Jul 12, 2022 · In JavaScript, arrays are passed by reference. Learn 5 different ways to clone an array, including using the spread operator.

  8. Copy an Array in JavaScript - Mastering JS

    Jul 29, 2020 · There are several easy ways to clone an array in JavaScript. You can use the Array#slice() method, or the spread operator. // Clone using `slice()` const arr2 = arr.slice(); …

  9. javascript - Copy array by value - Stack Overflow

    Basically, the slice() operation clones the array and returns a reference to a new array. For references, strings and numbers (and not the actual object), slice() copies object references …

  10. Copy Array Items Into Another Array in JavaScript

    Apr 28, 2025 · The Array.concat() method in JavaScript copies array items into another array by merging the original array with one or more arrays or values. JavaScript const a1 = [ 1 , 2 , 3 , …

  11. Some results have been removed