Tip 25: Combine Methods with Chaining

In this tip, you’ll learn to perform multiple array methods with chaining.

Chaining

Chaining is an old concept in programming. You can find it in many object-oriented languages. Like a lot of programming concepts, it actually sounds more complicated than it is in practice.

Here’s a quick definition: Chaining is immediately calling a method on a returned object (which in some cases is the original object) without reassigning the value first.

Okay, now forget that definition. For our purposes, chaining means that you can call several array methods in a row (as long as you get an array back). It’s a convenient way to perform several actions in a very clear manner.

Example

Think back to the last example: sending notifications to club members. The example was simplified (as examples always are). An actual array of club members would have a lot more data. It would have member status, email addresses, mailing addresses, position, and so on.

To keep things simple, let’s add just two fields: active and email.

Get hands-on with 1200+ tech skills courses.