跳到正文
Skillpedia
网站与界面(前端)75k · #2943

modern-array-methods

它能做什么

这项技能检查 JavaScript 代码,并在循环掩盖了意图的地方建议使用现代数组和对象方法。适用于希望代码更简洁、更易理解的开发者。

适用场景

  • ✓当你请智能体清理或现代化 JavaScript 循环的时候。
  • ✓当某个函数中有很长的 for 或 while 循环,用来过滤、转换或查找数据的时候。
  • ✓当你审查代码,并希望找到更安全的对象复制或数据转换方式的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/modern-array-methods/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/modern-array-methods/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我用现代数组方法重写 JavaScript 文件中的循环,让它更易读。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会找出可以用 map、filter、reduce、find 或 flatMap 替代的循环,并加以改写,使每一步的用途可以从方法名中看出来。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Use modern array and object methods

Modern array and object methods produce code that directly expresses intent — a filter() call self-documents that you're selecting items. Manual for loops obscure the purpose behind implementation details. These methods are also well-optimized by JavaScript engines and support chaining for concise data transformations.

Quick Reference

  • Use map() to transform arrays, filter() to select items, reduce() for aggregation
  • Use find() and findIndex() instead of manual loops with break
  • Use Object.entries() and Object.fromEntries() to transform objects
  • Use structuredClone() for deep copying instead of JSON.parse(JSON.stringify())

Check

Find loops in this file that could be replaced with modern array methods like map, filter, reduce, find, or flatMap.

Fix

Replace manual for/while loops with appropriate array methods to make the code more declarative.

Explain

Explain map, filter, reduce, find, flatMap, and Object.entries with practical examples.

Code Review

Review scripts, client components, and browser execution paths related to Use modern array and object methods. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/modern-array-methods

常见问题

为什么用 filter 而不是循环?

filter 调用一眼就能看出是在筛选项目,而手动循环会把这一点隐藏在细节中。

structuredClone 是做什么的?

这项技能建议用它进行深拷贝,取代较旧的 JSON.parse 和 JSON.stringify 方法。

这会改变代码的行为吗?

结果应当保持不变,但这项技能指出,应在浏览器中验证改动。

详情

作者的原始描述

Use when reviewing scripts, client components, bundles, or runtime behavior related to Use modern array and object methods. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2943
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能