Skip to content
Advertisement

How to make object with variable-based values in node.js

What I’m trying to do is keep a database of users in an object so I can assign values to each user, however I can’t find out a way to do it.

I’ve tried just doing var data = {} and then eval(`data.user_${user} = value`) but that only writes undefined. Any advice would be appreciated.

Advertisement

Answer

Try

data[`user_${user}`] = value
Advertisement