Answers for "javascript copy items into another array"

5

copy one array to another javascript

/* Copying arrays or parts of arrays in JavaScript */

var fruit = ["apple", "banana", "fig"]; // Define initial array.
console.log(fruit); // ["apple", "banana", "fig"]

// Copy an entire array using .slice()
var fruit2 = fruit.slice(); 
console.log(fruit2); // ["apple", "banana", "fig"]

// Copy only two array indicies rather than all three
// From index 0 (inclusive) to index 2 (noninclusive)
var fruit3 = fruit.slice(0,2); 
console.log(fruit3); // ["apple", "banana"]
Posted by: Guest on April-13-2020
0

js copy array into another

var destinationArray = Array.from(sourceArray);
Posted by: Guest on September-24-2020
3

javascript copy items into another array

var oldColors=["red","green","blue"];
var newColors = oldColors.slice(); //make a clone/copy of oldColors
Posted by: Guest on July-23-2019

Code answers related to "javascript copy items into another array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language