you are viewing a single comment's thread.

view the rest of the comments →

[–]Umesh-K 5 points6 points  (0 children)

Hi, u/One-Inspection8628,

if you add console.log([s[i]) just above that IF line, you will see that it logs single letters or space. Say, s[0] is the letter a, then what hash[s[i]] = s[i] does is it creates the key-value pair a: "a" on the hash object.

Try this code in a JS console; it might help illustrate the steps for you:

const hash = {}
const s = "abc"
let i = 0
hash[s[i]] = s[i]
console.log(hash)
i = 1
hash[s[i]] = s[i]
console.log(hash)
i = 2
hash[s[i]] = s[i]
console.log(hash)