댓글 검색 목록

[javascript] 배열의 모든 항목이 같은지 확인

페이지 정보

작성자 운영자 작성일 20-05-11 11:29 조회 674 댓글 0
const areEqual = arr => arr.length > 0 && arr.every(item => item === arr[0]);

// Or
const areEqual = arr => new Set(arr).size === 1;

// areEqual([1, 2, 3, 4]) === false
// areEqual(['hello', 'hello', 'hello']) === true

댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.