Method Chaining
noun
say it: “METH-ud CHAY-ning” /ˈmɛθəd ˈtʃeɪnɪŋ/
Calling one method on the result of the method before it, in a single line, such as scores.filter(...).map(...), so data flows through each step in turn.
What is Method Chaining in JavaScript?
Method Chaining — Calling a method on the result of the one before it, in one expression: each method hands its result to the next. With arrays, filter() then map() answers a question about a list in one readable line.
const scores = [120, 45, 300, 80];
const bigScores = scores.filter((s) => s >= 100).map((s) => `${s} pts`);
console.log(bigScores); // [ '120 pts', '300 pts' ]
In a sentence
- “With method chaining, one line kept the dogs, turned them into name tags and joined the tags with commas.”
Level: Apprentice · More JavaScript terms at this level
Updated