From the course: JavaScript: Best Practices for Functions and Classes

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use array destructuring

Use array destructuring - JavaScript Tutorial

From the course: JavaScript: Best Practices for Functions and Classes

Start my 1-month free trial

Use array destructuring

- [Instructor] Array destructuring is similar to object destructuring. It lets me efficiently create named references to array elements instead of needing to reference using array index values. The files for this video include the distanceTo.js module, which expects an array containing five values. My code then assigns those values to variables, which I use in the code that follows. In these mathematical manipulations, referencing the values using labels for what they represent makes it a lot easier to follow what's going on. I can use the same eslint prefer-destructuring rule that I use for objects to specify how I want to use array destructuring in my code. By default, the rule applies to both objects and arrays, but I can configure it to apply to only one if I want. I'll start by adding that rule to my eslintrc file for this video. And that's prefer-destructuring and then the value's going to be an array. I'm going…

Contents