Dino Geek, try to help you

What is the spread operator in JavaScript?


The spread operator, denoted by three dots `(…)` in JavaScript, is used to expand iterable objects into multiple elements. It is mainly used in array literals, function calls, and destructuring assignments.

For example, it can be used to combine arrays:

```
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];

let combined = […arr1, …arr2]; // [1, 2, 3, 4, 5, 6]
```

Or to clone an array:

```
let arr = [1, 2, 3];
let arrCopy = […arr]; // [1, 2, 3]
```

In a function call, it can be used to pass array elements as separate arguments:

```
let nums = [1, 2, 3];
console.log(Math.max(…nums)); // 3
```

And in destructuring assignments, it can be used to unpack elements from arrays or properties from objects:

```
let [first, …rest] = [1, 2, 3, 4, 5];
console.log(first); // 1
console.log(rest); // [2, 3, 4, 5]
```

```
let obj = {a : 1, b: 2, c: 3};
let {a, …others} = obj;
console.log(a); // 1
console.log(others); // {b: 2, c: 3}
```


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use