Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

array spread operator in javascript

let arr1 = ['A', 'B', 'C'];

let arr2 = ['X', 'Y', 'Z'];

let result = [...arr1, ...arr2];

console.log(result); // ['A', 'B', 'C', 'X', 'Y', 'Z']
// spread elements of the array instead of taking the array as a whole
Comment

ES6 spread

syntax:
...iterable
where, iterable is source like array, object, string etc 

const a=[1,2]
console.log(...a)
// prints 1 2

***spread operator makes a copy of source, not reference.
// ex. - if a & b are 2 arrays
a=[...b]
//changing a won't affect b & vice versa

*Also since it copies source, something like this is also possible:
const a=[5,1]
const b=[2]
const c=[...b,...a]
// c is [2,5,1]

*********************************************
For object just use {} instead of []
const a={ap:4}
const c={...a}

Comment

How javascript spread operator works?

var num = [2, 4, 6, 8, 10];
console.log(...num)
//expected output: 2 4 6 8 10
console.log(88, ...num, 99) 
// added extra new elements before and after the spread operator
//expected output: 88 2 4 6 8 10 99
Comment

javascript spread syntax

let arr1 = ['one', 'two'];
let arr2 = [...arr1, 'three', 'four', 'five'];
console.log(arr2); // ["one", "two", "three", "four", "five"]
Comment

Spread syntax in ES6

let arr1 = [1, 2, 3]
let func = (a, b, c) => a + b + c

console.log(func(...arr1)) // 6
Comment

es6 spread operator

spread operator uses
Comment

How to Use the Spread Operator in JavaScript

const newArray = ['firstItem', ...oldArray];
Comment

spread operator es6

[...fruits]
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to change sender name in nodemailer 
Javascript :: How to get element margin in React 
Javascript :: golang json time 
Javascript :: used as a function, Number() will convert another value 
Javascript :: pass props to svg 
Javascript :: reduce() method executes a reducer function on each element of the array and returns a single output value. 
Javascript :: stimulus controller 
Javascript :: angular material table generator 
Javascript :: fcus on element 
Javascript :: regular expression for twitter embedded tweets 
Javascript :: angular mat-calendar send to form 
Javascript :: angular 8 on mouseover 
Javascript :: icon with label in react native 
Javascript :: load js on only homepage wp 
Javascript :: conditionally add property to object 
Javascript :: @click:append 
Javascript :: Functions & Exec Context makePlans 
Javascript :: Line logger 
Javascript :: initialize back4app 
Javascript :: count selected gridview rows in javascript 
Javascript :: diable input javascript 
Javascript :: define classname next with more than one name 
Javascript :: show dropdown upwards and downward 
Javascript :: javascript document object model getElementsByClassName 
Javascript :: o que e window.onload js 
Javascript :: convert jquery hide function to pure javascript code 
Javascript :: create-react-app height issues with flex 
Javascript :: javascript reflections iterate all members 
Javascript :: for await range javascript 
Javascript :: javascript online programming test 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =