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

133
Views
Getting Values of Object from a variable

I have created a data sharing function, one to pass variables and one that gets these values as object as below.

var paramsObj = {};
var dataShareProvider = () => {
    return {
        getProperty: function () {
            return {
                paramsObj,
            };
        },
        setProperty: function (pKey1, pKey2, pKey3, pKey4, pKey5) {
            paramsObj.pKey1 = pKey1;
            paramsObj.pKey2 = pKey2;
            paramsObj.pKey3 = pKey3;
            paramsObj.pKey4 = pKey4;
            paramsObj.pKey5 = pKey5;
        },
    };
};

This is how i set the property values from a function.

dataShareProvider().setProperty(7, "active", true);

And i can access it another function as below

var userData = dataShareProvider().getProperty().paramsObj;

console.log(userData)

I need a small help in accessing values of objects. In my browser console, the values are as below enter image description here

I need values of pKey1, pKey2 and pKey3 to be used. I tried to it below but it gives me undefined

console.log(userData.pKey1) ==> undefined
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try It:

var paramsObj = {};
var dataShareProvider = () => {
    return {
        getProperty: () => window.paramsObj,
        setProperty: (...pKey) => pKey.forEach((value, index) => window.paramsObj[`pKey${index +1}`] = value)
    }
};

dataShareProvider().setProperty(7, "active", true);
const userData = dataShareProvider().getProperty();
console.log("pKey1: ", userData.pKey1) // output: 7
console.log("pKey2: ", userData.pKey2) // output: "active"
console.log("pKey3: ", userData.pKey3) // output: true

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!