Learn How to Create Chainable Methods in Javascript With a Practical Example
Chaining is a cool concept in programming, it is calling a method on a returned object without reassigning the value first. Suppose you have a users object: const users = [ {fname: 'Joseph', lname: 'Ada', age: 12}, {fname: 'Bernard', lname: 'Rutsell', age: 81}, {fname: 'Thompson', lname: 'Josaih', age: 41}, {fname: 'Dayo', lname: 'Adeoye', age: 17} ] And your task is to filter out users that are 18 and above. We can do this with the following lines of code which doesn’t use method chaining: ...