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

160
Views
reemplazar parámetros de URL con valores de un objeto

Tengo un objeto como este:

 let data = { url: "https://test.ir/apps/:type/:id/", params: { id: "com.farsitel.bazaar", type: "xyz", }, query: { ref: "direct", l: "en", }, };

Quiero reemplazar :type y :id en url con una clave equivalente a cada uno de los objetos params. ¿Cuál es la mejor solución en javascript?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Solución basada en hacer coincidir claves de params con el valor de una expresión regular de key url , seguida de una actualización de esa clave.

En la entrada: https://test.ir/apps/:type/:id/

En salida: https://test.ir/apps/xyz/com.farsitel.bazaar/

 let data = { url: "https://test.ir/apps/:type/:id/", params: { id: "com.farsitel.bazaar", type: "xyz", }, query: { ref: "direct", l: "en", }, }; let new_url = data.url.replace(/:(\w+)/g, (match, key) => data.params[key] || match); data.url = new_url; console.log(data);

about 4 years ago · Juan Pablo Isaza Report

0

¿Podría simplemente usar String.replace ?

 const data = { url: "https://test.ir/apps/:type/:id/", params: { id: "com.farsitel.bazaar", type: "xyz", }, query: { ref: "direct", l: "en", }, } const url = data.url.replace(":type", data.params.type).replace(":id", data.params.id); console.log(url)

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!