Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
Dynamically create OBJECTS NAME in javascript/jquery, NOT it's keys or values

How can you create an object with a dynamically created NAME? NOT dynamically created keys or values. I'd like to learn this in both jQuery and javascript

var com = "thing_"
var bined = "one"
var [com+bined] = {}

//so I can populate as such:
thing_one.key = value

I've googled my eyes out and tried a thousand things. Thanks in advance and apologies if I overlooked the obvious.

UPDATE: I accepted BadPiggie answer, as it does function as requested, however, I agree with Teemu and Terry's comments: this is not necessary and doesn't really have a use case.

It was fun to explore, thanks for all your input!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In javascript (In browser) global variables are property of window object. So you can do like this.

var com = "thing_"
var bined = "one"
window[com+bined] = {}

//you can populate as such:
thing_one.key = "some value";

console.log(thing_one);

Or you can use eval() but Not Recommended

var com = "thing_"
var bined = "one"
eval(`var ${com + bined} = {}`);

//you can populate as such:
thing_one.key = "some value";

console.log(thing_one);

about 4 years ago · Juan Pablo Isaza Report

0

You need to reference another object to stick your object in. If you did this in a class, you could do this[com+bined]={}. Outside of a class, you could do window[com+bined]={}.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!