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

200
Views
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 answers
Answer question

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 Report

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 Report

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 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!