Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2943

modern-array-methods

Skill này làm gì

Skill này xem code JavaScript và gợi ý các phương thức mảng và đối tượng hiện đại khi vòng lặp che giấu ý đồ. Skill dành cho lập trình viên muốn code ngắn hơn và dễ theo dõi hơn.

Khi nào nên dùng

  • ✓Khi bạn nhờ agent dọn dẹp hoặc hiện đại hóa các vòng lặp JavaScript.
  • ✓Khi một hàm có các vòng lặp for hoặc while dài để lọc, biến đổi hoặc tìm dữ liệu.
  • ✓Khi bạn rà soát code và muốn cách an toàn hơn để sao chép đối tượng hoặc biến đổi dữ liệu.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/modern-array-methods/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể viết lại các vòng lặp trong tệp JavaScript của tôi bằng phương thức mảng hiện đại để dễ đọc hơn không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm các vòng lặp có thể thay bằng map, filter, reduce, find hoặc flatMap. Nó viết lại sao cho mục đích của mỗi bước rõ ràng qua tên phương thức.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Vì sao dùng filter thay vì vòng lặp?

Lời gọi filter cho thấy ngay là đang chọn các mục, còn vòng lặp thủ công giấu điều đó trong chi tiết.

structuredClone dùng để làm gì?

Skill gợi ý dùng nó để sao chép sâu thay cho cách cũ là JSON.parse và JSON.stringify.

Điều này có thay đổi cách code hoạt động không?

Kết quả nên giữ nguyên, nhưng skill khuyên kiểm tra lại thay đổi trong trình duyệt.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2943
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự