What are higher-order array methods and how are they used?
Suggested answer
Higher-order array methods take callbacks and return new arrays (non-mutating): map(): Transforms every element: const doubled = nums.map(n => n * 2);. filter(): Returns elements passing the test: const evens = nums.filter(n => n % 2 === 0);. reduce(): Accumulates to a single value: const sum = nums.reduce((acc, n) => acc + n, 0);. find(): Returns first match (or undefined). findIndex(): Returns index of first match (or -1). some(): Returns true if any element passes. every(): Returns true if all pass. flat(): Flattens nested arrays. flatMap(): map then flat in one step. In LWC, these are used extensively for transforming data from wire service results into display-ready formats: this.options = records.map(r => ({ label: r.Name, value: r.Id }));
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.