第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

一個值在對象數(shù)組中重復多少次

一個值在對象數(shù)組中重復多少次

守候你守候我 2023-11-02 21:30:40
我有這個對象數(shù)組:const employees = [    {age: 35, name: "David" position: "Front-End"},    {age: 24, name: "Patrick" position: "Back-End"},    {age: 22, name: "Jonathan" position: "Front-End"},    {age: 32, name: "Raphael" position: "Full-Stack"},    {age: 44, name: "Cole" position: "Back-End"},    {age: 28, name: "Michael" position: "Front-End"},]我想得到這樣的結(jié)果:const employees = [    {position: "Front-End", count: 3},    {position: "Back-End", count: 2},    {position: "Full-Stack", count: 1},]這與該結(jié)果或最相似的結(jié)果有何關系?
查看完整描述

1 回答

?
繁星淼淼

TA貢獻1775條經(jīng)驗 獲得超11個贊

const employees = [

  { age: 35, name: 'David', position: 'Front-End' },

  { age: 24, name: 'Patrick', position: 'Back-End' },

  { age: 22, name: 'Jonathan', position: 'Front-End' },

  { age: 32, name: 'Raphael', position: 'Full-Stack' },

  { age: 44, name: 'Cole', position: 'Back-End' },

  { age: 28, name: 'Michael', position: 'Front-End' }

];


const obj = employees.reduce((val, cur) => {

  val[cur.position] = val[cur.position] ? val[cur.position] + 1 : 1;

  return val;

}, {});


const res = Object.keys(obj).map((key) => ({

  position: key,

  count: obj[key]

}));


console.log(res);


查看完整回答
反對 回復 2023-11-02
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號