“Salin array” Kode Jawaban

JavaScript Salin Array

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

// older method
const copy = Array.from(arr);
Batman

Java Copy Array

int[] a = {1,2,3,4,5};
int[] b = Arrays.copyOf(a, a.length);
T-Rex

Salin array javascript

const sheeps = ['Apple', 'Banana', 'Juice'];

// Old way
const cloneSheeps = sheeps.slice();

// ES6 way
const cloneSheepsES6 = [...sheeps];
Panzer

Array Salin JavaScript

var numbers = [1,2,3,4,5];
var newNumbers = Object.assign([], numbers);
Beautiful Bear

Salin 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
}
Mackerel

Salin array

let shallowCopy = fruits.slice() // this is how to make a copy
// ["Strawberry", "Mango"]
Ronnie

Jawaban yang mirip dengan “Salin array”

Pertanyaan yang mirip dengan “Salin array”

Lebih banyak jawaban terkait untuk “Salin array” di Rust

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya