"use strict" let base = {}; let user = "Вася" base.user = 1; for (let key in base) { alert("Имя: " + key) } 

How to make Вася alert ? It is necessary to make it work even if you do not know the user in advance.

  • base[user] = 1 - diraria

2 answers 2

You make a selection by key, and you want to show the values. So you need to get the values:

 base["user"] = user; for (let key in base) { alert("Имя: " + base[key]) } 

     "use strict" let base = {}; base["Вася"] = 1; for (let key in base) { console.log("Имя: " + key) }