Some times your interviewer ask you that count the every character in the string

const str = "how are you";
const objt = {}
for(let x of str){
       if(obj[x]){
                    obj[x] += 1;
               } else{
                             obj[x]=1
                            }
                  }
console.log(obj)
Result:
{
//
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.