Calculate the number of the same elements in the array

as shown in the array below, you want to get [{name: "zhang", conut: 4}, {name:" wang", conut: 2}, {name: "liu", conut: 2}] , or [{zhang: 4}, {wang: 2}, {liu: 2}] Thank you

.
let arr= [
            {name: "zhang", age: "20"},
            {name: "wang", age: "22"},
            {name: "zhang", age: "20"},
            {name: "liu", age: "23"},
            {name: "liu", age: "23"},
            {name: "wang", age: "22"},
            {name: "zhang", age: "20"},
            {name: "zhang", age: "20"},
        ]
May.23,2021

<script>
    let arr= [
            {name: 'zhang', age: '20'},
            {name: 'wang', age: '22'},
            {name: 'zhang', age: '20'},
            {name: 'liu', age: '23'},
            {name: 'liu', age: '23'},
            {name: 'wang', age: '22'},
            {name: 'zhang', age: '20'},
            {name: 'zhang', age: '20'},
    ]
    var map = {},
        newList = [];
    for (var i = 0; i < arr.length; iPP) {
      var obj = arr[i];
      if (!map[obj.name]) {
        newList.push({
          name: obj.name,
          count: 1
        });
        map[obj.name] = obj;
      } else {
        for (var j = 0; j < newList.length; jPP) {
          if (newList[j].name == obj.name) {
            newList[j].countPP;
            break;
          }
        }
      }
    }
    console.log("", newList)

</script>

   

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37a9c-2c0a5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37a9c-2c0a5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?