Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Create a Counter Object or Map in javascript

let string = 'kapilalipak';
const table={}; 
for(let char of string) {
  table[char]=table[char]+1 || 1;
}
// Output
{k: 2, a: 3, p: 2, i: 2, l: 2}
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #Create #Counter #Object #Map #javascript
ADD COMMENT
Topic
Name
7+9 =