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

308
Views
How to get the passed object name in JavaScript?

I have this code, I'm interested in whether it is possible to get the name of the passed object inside the useConf function, namely "container__wrapper", and not "Object".

const conf = {
    container__wrapper : {
        style : {
            width : '100%'
        }
    } as Component,

    toolbar : {
        ui: "default"
    } as Component,
};

const useConf = (config: Object) => {
    return config.constructor.name; // Return "Object"
}

console.log(
    useConf(conf.container__wrapper);
);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can't, but you can add a name property to your object for this purpose, e.g:

const conf = {
    container__wrapper : {
        name: 'container__wrapper',
        style : {
            width : '100%'
        }
    } as Component,

    toolbar : {
        name: 'toolbar',
        ui: "default"
    } as Component,
};

const useConf = (config: Object) => {
    return config.name; // Returns "container__wrapper"
}

console.log(
    useConf(conf.container__wrapper);
);
about 4 years ago · Juan Pablo Isaza Report

0

Like this:

const useConf = (config: Object) => {
    return Object.keys(config)[0] // Return "first key name"
}
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!