OPEN HYPER STEP
← 목록으로 (JavaScript)
JS · 18 / 34
js
CHAPTER 18 / 34
읽기 약 2
SYNTAX

배열 고급 메서드: find some every flat


핵심 개념

find는 조건을 만족하는 첫 요소 반환, findIndex는 그 인덱스 반환, some은 하나라도 만족하면 true, every는 모두 만족해야 true입니다. flat은 중첩 배열을 평탄화하고, flatMap은 map 후 flat을 수행합니다. includes는 값 포함 여부를 확인합니다. 각 메서드를 지우며 데이터 검색 시스템이 붕괴되는 것을 확인하십시오.

코드 분석
JS📋 코드 (20줄)
const units = [
    { id: 1, model: 'T-800', threat: 8, active: true },
    { id: 2, model: 'T-1000', threat: 10, active: true },
    { id: 3, model: 'T-X', threat: 9, active: false },
    { id: 4, model: 'T-600', threat: 6, active: true },
  ];

  const found = units.find(u => u.threat >= 10);
  const hasInactive = units.some(u => !u.active);
  const allActive = units.every(u => u.active);
  const highThreat = units.filter(u => u.threat >= 9).map(u => u.model);

  const nested = [[1,2],[3,4],[5,6]];
  const flat = nested.flat();

  document.write('<div style="color:#10b981;margin-bottom:4px;">FIND (threat≥10): ' + found.model + '</div>');
  document.write('<div style="color:#f59e0b;margin-bottom:4px;">SOME (inactive exists): ' + hasInactive + '</div>');
  document.write('<div style="color:#22c55e;margin-bottom:4px;">EVERY (all active): ' + allActive + '</div>');
  document.write('<div style="color:#888;margin-bottom:4px;">HIGH THREAT: ' + highThreat.join(', ') + '</div>');
  document.write('<div style="color:#888;">FLAT: ' + flat.join(', ') + '</div>');

AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
Claude

무료: Sonnet 4.6 / Pro $20/mo: Opus 4.6

이 JS '배열 고급 메서드' 코드의 잠재적 버그와
메모리 누수·this 바인딩·비동기 경합 위험을
분석해서 프로덕션 수준으로 개선해줘.
ChatGPT

무료: GPT-5.5 / Plus $20/mo: GPT-5.5 Pro

'배열 고급 메서드'를 실제 서비스에서 어떻게 쓰는지
구체적 사례 3개와 복사 가능한 코드를
초보자가 이해할 수 있게 보여줘.
Gemini

무료: 2.5 Flash / Pro $19.99/mo: 3.1 Pro

이 JS '배열 고급 메서드' 관련 코드 전체의 실행 흐름을 분석하고
성능 병목과 최적화 방안을 우선순위로 알려줘.
Grok

무료: Grok 4.1 / SuperGrok $30/mo

'배열 고급 메서드'에서 개발자들이 가장 많이 하는
실수 Top 3을 솔직하게 알려주고
2026년 권장 패턴을 함께 알려줘.

⭐ 이것만 기억하세요
배열 고급 메서드: find some every flat 이 3가지만 확실히 잡으세요
1.배열에서 조건에 맞는 첫 번째 값만 필요한데 filter를 쓰면 전체를 순회하고 배열을 반환해서 비효율적입니다
2.find는 첫 매칭 하나, some은 하나라도 true면 true, every는 전부 true여야 true, flat은 중첩 배열을 펼칩니다
3.다음 챕터에서 배열과 객체를 한 번에 분해하는 구조분해 할당과 스프레드를 배웁니다


공유하기
진행도 18 / 34