1

For instance, in this function even if i already assigned the value of a. The program considers a as An individual letter and does not add the value assigned to it in the html program.

let obj={}

function reg() {
let a = document.getElementById('user').value 
let b = document.getElementById('pass').value
obj.a=b

}

Output= a:the assigned value for b

Pls clarify my doubt.

Daran
  • 17
  • 2
  • square brackets instead of a dot. `obj[a] = b`. The content of the brackets is evaluated as an expression, and its result is used as the key. –  Jul 04 '20 at 20:06

1 Answers1

0

Hey there this problem should be solved by

obj[a]=b

This is because the object.key method only works if the key is already present in the object

Happy coding and do let me know if you have any queries!

Yash.S.Narang
  • 518
  • 4
  • 13
  • Whether or not the key already present has no impact on how the `object.key` syntax works. –  Jul 04 '20 at 20:20