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

201
Vistas
I need to extract text after = for each value seperated by semicolon in javascript. I have done it but wondering if there is a better approach

My working code:

const myString = "a=*aaa;b=*bbb";
let params = [];
myString.split(";").forEach(element => {
  let zz = element.split('=');
  params.push(zz[1]);
});
console.log(params.map((element, index) => index + '=' + element).join(';'));

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can make params a const

It is an array, and you are just appending items.

You can merge the two statements in the loop

You are letting a variable, and then just using it once.

You can convert the whole process into a .map

Instead of creating an empty array and appending things to it, you can map the array of ";" separated strings into a corresponding array of the strings you want.

Applying all 3 steps, you get this:

const myString = "a=*aaa;b=*bbb";

const params = myString.split(";").map(
  element => element.split('=')[1]
);

console.log(params.map((element, index) => index + '=' + element).join(';'));

about 4 years ago · Juan Pablo Isaza Denunciar

0

Here is a shorter approach, but think about if you want an approach like that. It is not easy to read.

const myString = "a=*aaa;b=*bbb";

const params =
  myString
  .split(";")
  .map((element, index) => {
    let zz = element.split('=');

    return `${index}=${element.split("=")[1]}`;
  })
  .join(";");

console.log(params);

about 4 years ago · Juan Pablo Isaza Denunciar

0

I would put them in an object.

const myString = "a=*aaa;b=*bbb";
let params = {};
myString.split(";").forEach(element => {
  let zz = element.split('=');
  params[zz[0]] = zz[1];
});
console.log(params);
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