前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >JavaScript | 获取数组中的单词并统计出现次数

JavaScript | 获取数组中的单词并统计出现次数

作者头像
HTML5学堂
发布于 2018-03-13 08:11:44
发布于 2018-03-13 08:11:44
5.2K0
举报
文章被收录于专栏:HTML5学堂HTML5学堂
HTML5学堂(码匠):如何通过JavaScrip实现数组元素的查找?在一个数组当中,找到所有的单词,并统计每个单词出现的次数。

功能需求

在一个自定义数组当中,包含多个单词,请使用JavaScipt获取数组中的每个单词,并统计出每个单词出现的次数。

功能分析与实现思路

可以借助对象的特性,使用对象属性表示数组中的具体单词,使用对象属性的属性值表示相应单词出现的次数。

完整的代码实现

代码输出结果

相关知识

对象属性的两种表示方法

对于对象来说,可以使用“对象.属性”的方法来表示,也可以使用“对象[属性]”的方法来表示。

for in循环

for-in循环用于遍历对象中的所有属性和属性值。很适用于不确定对象中有什么属性的时候使用。基本语法为:

for(变量 in 对象){ 语句 }

其中随着循环的进行,变量表示对象中的各个属性,而“对象[变量]”则表示对象中属性对应的属性值。

代码解析

1. sort方法,是针对数组进行排序,这个步骤可以省略,不排序也能够直接输出。

2. 通过for循环,检测数组中的每个值是否在obj中存在,如果不存在,则设置这个属性,并将属性值赋值为1,如果当前obj中已存在相应单词,则令属性值+1。

3. 到循环结束,即可获得到所有的单词以及相应单词的个数。

4. 通过for-in循环,遍历并输出对象中的所有属性和属性值。

备注:实现该功能需求的方法有多种,也可以通过其他手段或方法来实现。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-02-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 懂点君 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
TensorFlow Lite for Microcontroller
Microcontrollers (MCUs) are the tiny computers that power our technological environment. There are over 30 billion of them manufactured every year, embedded in everything from household appliances to fitness trackers.
用户6026865
2023/03/03
1K0
TensorFlow Lite for Microcontroller
Hello Edge: Keyword Spotting on Microcontrollers
- Hello Edge: Keyword Spotting on Microcontrollers -
用户6026865
2023/03/02
6020
Hello Edge: Keyword Spotting on Microcontrollers
【云+社区年度征文】TinyML实践-2:How TinyML Works?
对于Tensorflow最大需求是能够在桌面系统中训练并运行模型,这种需求影响了很多设计决策,例如为了更低的延迟和更多的功能而增加可执行文件的大小。云端服务器上,RAM以GB为衡量单位,存储空间以TB为单位,几百兆字节的二进制文件通常不是问题。
flavorfan
2020/12/07
1.8K0
【云+社区年度征文】TinyML实践-2:How TinyML Works?
Sensory’s TrulyHandsfree and Arm’sCortex-M55
Efficient wake word recognition on microcontrollers with Cortex-M55 and Helium technology for use in consumer and automotive products that include more and more AI features for voice applications.
用户6026865
2022/09/02
3370
Sensory’s TrulyHandsfree and Arm’sCortex-M55
Cloud AI, Edge AI, Endpoint AI. What’s the Difference?
Today, the majority of what we call artificial intelligence (AI) is machine learning (ML), a subset of AI that involves machines learning from sets of data. In general, the greater the amount of data to learn from, the more the AI is able to infer meaning and the more useful it becomes.
用户6026865
2022/09/02
4500
Cloud AI, Edge AI, Endpoint AI. What’s the Difference?
Sensory & ST Micro – Natural Language on CM7 Core MCU
Sensory is making an announcement with our partner ST Micro, and we are intentionally NOT being vague. This partnership is designed to make it easy to develop or prototype and we have created a very clear path for interested clients. This partnership combines a few key elements that make it VERY special and easy to develop speech-based or voice controlled products:
用户6026865
2022/09/02
2230
Sensory & ST Micro – Natural Language on CM7 Core MCU
水果图像识别:基于 Arduino 和 TensorFlow Lite Micro
特邀博文 / Dominic Pajak 和 Sandeep Mistry,来自 Arduino 团队
CV君
2020/11/23
2.2K0
水果图像识别:基于 Arduino 和 TensorFlow Lite Micro
TinyML实践-1:What & Why TinyML?
机器/深度学习已经如火如荼,各种炫目的效果呈现不穷,笔者也复现一些如stackoverflow assistence、头像动漫化等,但大都需要强大算力,“终端(手机)+云服务器”是基本结构。去年关注到Google TFLite Micro(TFLM)及技术,可以将Tensorflow 模型部署到嵌入式的端末设备(比如arm cortex M4 64M)。恰好手头有一个农业物联网项目,利用嵌入式设备识别牲畜的活动状态,应用了这一个技术。这段时间项目间隙,记录下开发过程的一些心得体会。
flavorfan
2020/12/07
2.6K1
TinyML实践-1:What & Why TinyML?
CloudBluePrint - Chapter 1.9: Embracing Generative AI in Cloud Application Archi
In the rapid advancement of technology, Generative AI is increasingly becoming a key driver of innovation. By learning from large datasets, it can generate new content and has a wide range of applications, including text generation, image generation, music creation, and code generation. Major cloud providers offer a variety of AI services that enable enterprises and developers to easily build and deploy Generative AI applications. This article provides a detailed comparison of the cloud services for Generative AI from AWS, GCP, Azure, Alibaba Cloud, and Tencent Cloud.
行者深蓝
2024/05/31
1120
A review on TinyML: State-of-the-art and prospects PartI
Machine learning has become an indispensable part of the existing technological domain. Edge computing and Internet of Things (IoT) together presents a new opportunity to imply machine learning techniques at the resource constrained embedded devices at the edge of the network.
用户6026865
2022/09/02
3690
A review on TinyML: State-of-the-art and prospects PartI
Data Center Manager using OpenStack
OpenStack facilates users to provision and manage cloud services in a convenient way, including compute instances, storage and network. Meanwhile, data center requires a converged, uniformed management solution to provision, monitor, manage and diagnostic servers, and even collaborate seamlessly with other existing IT solution.This data center manager addresses this requirement by providing an open-source, easy-to-customizing, converged management solution based on OpenStack technologies, plugin mechanisms.
段立功
2022/06/13
3300
开源软件的商业模式
Business models for open-source software / 开源软件的商业模式
开源社
2022/04/11
2.3K0
没有硬件,也可以运行与测试 TFLite 应用
提到人工智能和机器学习(Marchine Learning,ML),你的脑海里是否立即会浮现计算中心、高端 GPU、成百上千的 TPU 等等。实际上,随着嵌入式设备、移动终端以及近年来物联网(Internet of Things,IoT)的发展,人工智能离我们越来越近。手机、智能音箱、电话手表,甚至控制开关,都配备有一定的人工智能。特别是物联网和智能家居的快速发展,机器学习在微型低功耗设备上应用得越来越广泛。
云水木石
2020/06/24
1.4K0
AIoT应用创新大赛-基于TFML的迁移学习实践
NXP eIQ平台提供了嵌入式平台集成化的机器学习应用部署能力,支持BYOD(Bring Your Own Data)和BYOM(Bring You Own Model)的两种建模应用的工作流。
flavorfan
2022/02/23
2.2K0
AIoT应用创新大赛-基于TFML的迁移学习实践
How to Grow Your Career as a JavaScript Developer?
JavaScript is one of the most beloved and desirable programming languages to learn in 2019. JS development is a hot career option in the programming world. It is one of the best-paying programming languages to get familiar with. It was developed by Brendan Eich back in 1995. Officially, the popular programming language is known as the ECMAScript.
用户4095052
2019/01/09
7110
How to Grow Your Career as a JavaScript Developer?
Langchain 介绍与入门
安装 LangChain CLI 和 LangServe, 安装langchain-cli会自动安装LangServe
JadePeng
2024/03/01
1.1K0
台湾初创企业CES涵盖广泛技术领域
在过去的三年中,台湾科学技术部(MOST)将初创公司带入了CES。今年,它与台湾科技竞技场组织的虚拟展馆将接待100家初创公司,分为五个类别:智能生活,公益科技,网络安全和云,医疗保健和移动科技。在两次新闻发布会期间,有24家初创公司预览了他们的CES演示文稿,从而预示了展馆的展示内容。
木樾233
2021/01/15
8170
ARM 急社招工程师
XPD Software Engineering 地点: 上海市·闵行区, 广东·深圳市 Introduction ArmChina XPU Product Development (XPD) division is looking for passionate Computing Subsystem/SoC individuals to form a best-in-class engineering team. Responsibilities • Understand system requireme
刘盼
2022/03/04
4310
STM&Sensory Enable Embedded VUI Through STM32Cube Ecosystem
TM32 MCUs pair with Sensory’s VoiceHub technology to streamline development of voice-based user interfaces on wearables, IoT, and smart-home applications
用户6026865
2022/09/02
4210
Qualcomm Snapdragon 855 vs Exynos 9820 vs Kirin 980
Three major smartphone SoC designers have now detailed their next-generation designs, which will power smartphones throughout 2019. Huawei was first with its Kirin 980, already powering the Huawei Mate 20 series. Samsung followed, announcing its Exynos 9820. Now Qualcomm’s just announced the Snapdragon 855.
用户9732312
2022/05/13
4530
Qualcomm Snapdragon 855 vs Exynos 9820 vs Kirin 980
推荐阅读
相关推荐
TensorFlow Lite for Microcontroller
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档