- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Count characters case insensitive
We are given a string and are required to write a function that returns the frequency of each character in the array. And we should not take the case of characters into consideration.
To do this the best way would be iterating over the string and preparing an object with key as characters and their frequency as value.
The code for doing this will be −
Example
const string = 'ASASSSASAsaasaBBBASvcdNNSASASxxzccxcv'; const countFrequency = str => { const frequency = {}; for(char of str.toLowerCase()){ if(!frequency[char]){ frequency[char] = 1; }else{ frequency[char]++; }; }; return frequency; }; console.log(countFrequency(string));
Output
The output of the above code in the console will be −
{ a: 10, s: 11, b: 3, v: 2, c: 4, d: 1, n: 2, x: 3, z: 1 }
- Related Articles
- JavaScript Check for case insensitive values?
- How to use case-insensitive switch-case in JavaScript?
- How to perform Case Insensitive matching with JavaScript RegExp?
- MySQL case-insensitive DISTINCT?
- JavaScript filter an array of strings, matching case insensitive substring?
- Case-insensitive Dictionary in C#
- Case insensitive search in Mongo?
- How to do case insensitive string comparison of strings in JavaScript
- Case-insensitive string comparison in C++
- MongoDB query with case insensitive search?
- Perform case insensitive SELECT using MySQL IN()?
- MongoDB query for specific case insensitive search
- How to make jQuery attribute selector case insensitive?
- How to perform case-insensitive search in Oracle?
- How to compare two string arrays, case insensitive and independent about ordering JavaScript, ES6

Advertisements