New course! Every coder should learn Generative AI!
Try a free lesson0
How does this work?
this code sorts a string into an object adding together the common words. var word = "Hello World"; var chars = {}; for(let char of word){ if(!chars[char]){ chars[char]=1 }else{ chars[char]++ } } the obj now is now {"H": 1, "e":1, "l":3, "o":2, "W":1, "r":1, "d":1} How does it know to add like characters? How does it know which is the key or the value? Does adding obj[anything] transform anything into a object?
0 Answers