Categories
JavaScript Answers

How to pass an array as a function parameter in JavaScript?

Spread the love

To pass an array as a function parameter in JavaScript, we use the spread operator.

For instance, we write

const x = ["p0", "p1", "p2"];
func(...x);

to call func with the entries of x as arguments with the spread operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.