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

148
Views
How to get the key name dynamically from the list in Nodejs

How to get the key name dynamically from the list and push it to an array using NodeJS.

This is my string { PRICE: '12', TYPE: 'Electronics' }

I want to push the key name PRICE, TYPE to an array like below:

const myArray = ["PRICE", "MyOrg::PRICE", "TYPE", "MyOrg::TYPE"]

I don't know how to get the key name dynamically from the list and push it to an array - can someone pls help me with this. Thanks.

Sample code:

const test = async () => {

        const myList =  { TYPE: '12', REGION: 'Electronics' }

        // Execpted array like below
        const myArray = ["PRICE", "MyOrg::PRICE", "TYPE", "MyOrg::TYPE"]


  };
  
  test();
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You could simply do Array.concat with Object.keys

const myList = { TYPE: '12', REGION: 'Electronics' };
let myArray = ['PRICE', 'MyOrg::PRICE'];

myArray = myArray.concat(Object.keys(myList));
console.log(myArray);

about 4 years ago · Juan Pablo Isaza Report

0

Question doesn't really make sense. The following code generates the output that you are asking for, but it doesn't seem useful.

const myList = { "PRICE": 12, "TYPE": "Electronic" };

const myArray = [];

Object.keys(myList).forEach( function (key) {
    // Loop through all the keys
    myArray.push(key)
    myArray.push("MyOrg::"+key)
})

console.log(myArray)
// Expected output
// myArray == ["PRICE", "MyOrg::PRICE", "TYPE", "MyOrg::TYPE"]

about 4 years ago · Juan Pablo Isaza Report

0

You just need variable substitution in your code, that you get by enclosing variable with curly braces like this ${variable}.

const myList =  { TYPE: '12', REGION: 'Electronics' }
array = Object.keys(myList)
myArray = []
for (let element of array){
    myArray.push(element, `MyOrg::${element}`)
}
console.log(myArray)

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!