댓글 검색 목록

[javascript] 두 배열 비교

페이지 정보

작성자 운영자 작성일 20-05-11 11:31 조회 643 댓글 0
// Using stringify
// `a` and `b` are arrays
const compare = (a, b) => JSON.stringify(a) === JSON.stringify(b);

// Or
const compare = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);

// compare([1, 2, 3], [1, 2, 3]) === true
// compare([1, 2, 3], [1, '2', 3]) === false

댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

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