Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda