0

Javascript object keys

var userName = "someName"; var userEmail = "aname@some.thing"; var dataObj = { userName : userEmail } // I need this // dataObj should be { "someName" : "aname@some.thing" }

20th Oct 2020, 1:13 PM
Rishi
5 Antworten
+ 5
well then u would have to do it like this: dataObj[userName] = userEmail
20th Oct 2020, 1:37 PM
maf
maf - avatar
+ 2
Then go through maf idea ®!$]-[!
20th Oct 2020, 3:59 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
var dataObj = {} dataObj["someName"] = "aname@some.thing" console.log(dataObj["someName"]) Have a look to this
20th Oct 2020, 1:41 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
@maf thanks . it worked!!
21st Oct 2020, 5:57 AM
Rishi
0
丹ⓨㄩک廾 I can't directly give the values and I need to use the variable
20th Oct 2020, 2:12 PM
Rishi