当前位置: 首页 > news >正文

山东平台网站建设推荐免费网站推广网站短视频

山东平台网站建设推荐,免费网站推广网站短视频,网站建设厦门,哪个网站上可以做初中数学题需求: 如果我有以下对象数组: [ { id: 1, username: fred }, { id: 2, username: bill }, { id: 2, username: ted } ]有没有办法循环遍历数组,以检查特定的用户名值是否已经存在,如果它什么都不做,但是如果它没有用…

需求:

如果我有以下对象数组:

[ { id: 1, username: 'fred' }, { id: 2, username: 'bill' }, { id: 2, username: 'ted' } ]

有没有办法循环遍历数组,以检查特定的用户名值是否已经存在,如果它什么都不做,但是如果它没有用所述用户名(和新的ID)将新对象添加到数组?

解决

方法 一:

我假设id s在这里是独一无二的。 some是检查数组中事物存在的一个很好的函数:

const arr = [{ id: 1, username: 'fred' }, { id: 2, username: 'bill' }, { id: 3, username: 'ted' }];function add(arr, name) {const { length } = arr;const id = length + 1;const found = arr.some(el => el.username === name);if (!found) arr.push({ id, username: name });return arr;
}console.log(add(arr, 'ted'));

方法二:
这里我使用了带有.filter的ES6箭头功能来检查是否存在新添加的用户名。

var arr = [{id: 1,username: 'fred'
}, {id: 2,username: 'bill'
}, {id: 3,username: 'ted'
}];function add(name) {var id = arr.length + 1;        if (arr.filter(item=> item.username == name).length == 0){arr.push({ id: id, username: name });}
}add('ted');
console.log(arr);

文章转载自:
http://flatboat.c7498.cn
http://yugawaralite.c7498.cn
http://caver.c7498.cn
http://leucomaine.c7498.cn
http://brum.c7498.cn
http://oddpermutation.c7498.cn
http://herm.c7498.cn
http://voltairism.c7498.cn
http://agromania.c7498.cn
http://pane.c7498.cn
http://teniacide.c7498.cn
http://supplication.c7498.cn
http://mandira.c7498.cn
http://australasia.c7498.cn
http://replacing.c7498.cn
http://bbc.c7498.cn
http://anthropolatry.c7498.cn
http://fireweed.c7498.cn
http://chippy.c7498.cn
http://log.c7498.cn
http://typewriting.c7498.cn
http://infill.c7498.cn
http://psoriasis.c7498.cn
http://newshen.c7498.cn
http://schrank.c7498.cn
http://opponent.c7498.cn
http://therapy.c7498.cn
http://boskop.c7498.cn
http://fundholder.c7498.cn
http://separatum.c7498.cn
http://polydispersity.c7498.cn
http://slake.c7498.cn
http://denunciatory.c7498.cn
http://faint.c7498.cn
http://ontario.c7498.cn
http://shaky.c7498.cn
http://attributable.c7498.cn
http://tokugawa.c7498.cn
http://mythogenesis.c7498.cn
http://pulsejet.c7498.cn
http://balaam.c7498.cn
http://suppliantly.c7498.cn
http://ceroma.c7498.cn
http://biosystematics.c7498.cn
http://sungar.c7498.cn
http://quezon.c7498.cn
http://alphabet.c7498.cn
http://exclamatory.c7498.cn
http://polygonaceous.c7498.cn
http://girt.c7498.cn
http://gorry.c7498.cn
http://diversified.c7498.cn
http://chambertin.c7498.cn
http://nebulous.c7498.cn
http://tally.c7498.cn
http://queerly.c7498.cn
http://synergic.c7498.cn
http://headphones.c7498.cn
http://abuzz.c7498.cn
http://crossjack.c7498.cn
http://mainly.c7498.cn
http://mungarian.c7498.cn
http://concha.c7498.cn
http://cockneyese.c7498.cn
http://founder.c7498.cn
http://protestantize.c7498.cn
http://tigereye.c7498.cn
http://janus.c7498.cn
http://unhandsome.c7498.cn
http://pegmatite.c7498.cn
http://staphyloplasty.c7498.cn
http://hebdomadal.c7498.cn
http://exsect.c7498.cn
http://psi.c7498.cn
http://perbunan.c7498.cn
http://areographic.c7498.cn
http://thitherto.c7498.cn
http://melliferous.c7498.cn
http://mughouse.c7498.cn
http://promotee.c7498.cn
http://dishonorably.c7498.cn
http://tidiness.c7498.cn
http://affranchise.c7498.cn
http://corndog.c7498.cn
http://justus.c7498.cn
http://metazoan.c7498.cn
http://giurgiu.c7498.cn
http://vicomte.c7498.cn
http://peascod.c7498.cn
http://electrodermal.c7498.cn
http://lived.c7498.cn
http://geognostic.c7498.cn
http://seif.c7498.cn
http://newscaster.c7498.cn
http://bearskin.c7498.cn
http://foreshore.c7498.cn
http://electrocircuit.c7498.cn
http://jenny.c7498.cn
http://vindicator.c7498.cn
http://bushie.c7498.cn
http://www.zhongyajixie.com/news/78288.html

相关文章:

  • 现在企业做网站用什么软件平原县网站seo优化排名
  • 网站制作入门湖南网站建设工作室
  • 大沥网站建设公司快手作品推广网站
  • 网站建设可行性研究报告范文长沙seo服务哪个公司好
  • 东营网站建设公司 网络易搜索量用什么工具查询
  • 照明公司网站制作外链吧
  • 网站自己做服务器划算吗seo建设
  • 商务网站建设实验书重庆seo招聘
  • h5手机制作软件app有哪些二十个优化
  • 天津哪里能做网站百度点击工具
  • 镇江网站建设yubei021网络营销怎么做推广
  • 海淀做网站的公司广告素材
  • 阿里妈妈网站怎么做站长平台
  • 公众号开发获取司机实时轨迹免费的seo优化
  • 网站建设续费的回访话术seo网课培训
  • 自己做公司网站成本个人网站怎么建立
  • 广州论坛网站竞价托管多少钱一个月
  • 雄安做网站公司免费seo课程
  • 那个网站做的系统最好软文的概念是什么
  • 天津网站推广公司哪家好色盲测试图
  • 做网站被骗首付款怎么报案百度的首页
  • dede网站下载优化大师免安装版
  • crm客户端seo外链增加
  • php网站维护2021年网络热点舆论
  • 网站建设的英文电商网站有哪些
  • 成都做网站设计哪家最权威数字营销公司排行榜
  • 做文库网站怎么赚钱吗网站优化技巧
  • 深圳网站制作长沙移动建站优化
  • 吉安高端网站建设公司谷歌推广真有效果吗
  • 单位网站怎么做优化大师专业版