Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript array concat spread operator

const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
Comment

javascript merge two array with spread operator

const a = ['to', 'code'];
const b = ['learning', ...a, 'is', 'fun']; 
console.log(b); //> ['learning', 'to', 'code', 'is', 'fun']
Comment

How to Concatenate or Merge Arrays With the Spread Operator in JavaScript

let femaleNames = ["Daniel", "Peter", "Joe"];
let maleNames = ["Sandra", "Lucy", "Jane"];

let allNames = [...femaleNames, ...maleNames];

console.log(allNames); // ["Daniel","Peter","Joe","Sandra","Lucy","Jane"]

// It's also important to know that we can use the same approach for as many arrays
// as we have. We can also add individual elements within the array:

let femaleNames = ["Daniel", "Peter", "Joe"];
let maleNames = ["Sandra", "Lucy", "Jane"];
let otherNames = ["Bill", "Jill"];

let moreNames = [...otherNames, ...femaleNames, ...maleNames];
let names = [...moreNames, "Ben", "Fred"];


// This saves us the stress of using a complicated syntax like the concat() method
Comment

PREVIOUS NEXT
Code Example
Javascript :: AWS S3 JavaScript example 
Javascript :: javascript onclick open url same window 
Javascript :: var_dump in javascript 
Javascript :: joi validation custom message in node 
Javascript :: jspdf attach image file 
Javascript :: how to make hide/show btn in js 
Javascript :: get looping in jquery 
Javascript :: javascript join 
Javascript :: difference between call and apply in js 
Javascript :: chamar arquivo javascript no html 
Javascript :: javascript add to array 
Javascript :: regular expression javascript password strength 
Javascript :: js narrate text 
Javascript :: jest mock react-redux hooks 
Javascript :: jquery check if clicked outside div 
Javascript :: add bootstrap to angular 13 
Javascript :: remove underline from hyperlink react 
Javascript :: nginx redirect location to port 
Javascript :: javascript check if array has duplicates 
Javascript :: javascript random integer 
Javascript :: html javascript type 
Javascript :: Remove duplicate items form array using reduce() method. 
Javascript :: exit from fullscreen 
Javascript :: append object to object javascript 
Javascript :: subtract dates javascript 
Javascript :: js paste 
Javascript :: how to use secondary color in material ui useStyle 
Javascript :: how to catch and throw error js 
Javascript :: javascript remove property from object 
Javascript :: await useeffect react 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =