7 ES6 Spread Operator Tricks Every Developer Should Know

7 ES6 Tricks Make You Write Less And Do More.

fatfish
2 min readJan 4, 2023

Preface

ES6 provides a new operator called the spread operator, which is composed of three points (…).

The spread operator allows you to expand the elements of an iterable object, such as map, array, set and object. That even allows us to write less and do more.

Example:

In this article, I want to teach you 7 spread operator tricks.

1. A better way to use the array’s push() method

We all know that the push() method supports passing multiple indeterminate parameters.

Usually, we use the apply() method to fill the array, but that is not convenient after all.

--

--

fatfish
fatfish

Written by fatfish

Hi friends, I am a front-end engineer from Alibaba, let’s code happily together.

Responses (3)