Answers for "Copy an Array"

21

javascript copy an array

let arr =["a","b","c"];
// ES6 way
const copy = [...arr];

// older method
const copy = Array.from(arr);
Posted by: Guest on July-02-2020
0

copy an array

// Copy an array
fn main() {
    let arr = ["a","b","c"];
    let mut another = arr.clone();  // make a copy
    println!("copy of arr = {:?} ", another);
    another[1] = "d";          // make a change
    assert_eq!(arr, another);  // panic, no longer equal
}
Posted by: Guest on September-30-2021
0

Copy an Array

let shallowCopy = fruits.slice() // this is how to make a copy
// ["Strawberry", "Mango"]
Posted by: Guest on July-02-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language