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

156
Views
Cómo obtener el nombre de la clave dinámicamente de la lista en Nodejs

Cómo obtener el nombre de la clave dinámicamente de la lista y enviarlo a una matriz usando NodeJS.

Esta es mi cadena { PRICE: '12', TYPE: 'Electronics' }

Quiero enviar el nombre de la clave PRICE , TYPE a una array como la siguiente:

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

No sé cómo obtener el nombre de la clave dinámicamente de la lista y enviarlo a una matriz. ¿Puede alguien ayudarme con esto? Gracias.

Código de muestra:

 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

Simplemente podría hacer Array.concat con 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

La pregunta realmente no tiene sentido. El siguiente código genera el resultado que está solicitando, pero no parece útil.

 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

Solo necesita la sustitución de variables en su código, que obtiene encerrando la variable con llaves como esta ${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!