Menu Close
  • Categories
  • Tags
  • About
Close
    • SLOW LIFE
    • Categories
    • Tags
    • Search

    [javascript] 배열 내에서 중복 카운팅

    Published: 2022-07-21 by mascaradee Creative Commons Licence

    • Categories:
    • javascript 76
    • Tags:
    • Map 1
    • foreach 2
    • javascript 4
    • 배열 내에서 중복 카운팅

    배열 내에서 중복 카운팅

    
    const arr = ['a', 'a', 'b', 'b'];
    
    const newArr = new Map();
    arr.forEach( ele => {
      newArr[ele] = (newArr[ele] || 0) + 1;
    });
    
    // Map(0) {a: 2, b: 2, size: 0}
    
    Back to Top
    ← [tips] frontend-loadmap-2022 [javascript] split(), join()으로 replaceall구현하기 →

    A gem-based responsive simple texture styled Jekyll theme.

    Theme Simple Texture developed by Yi Zeng, powered by Jekyll.

    Back to Top