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

258
Views
¿Cómo elimino palabras que comienzan con la palabra clave en el valor del objeto? javascript

Tengo una matriz como esta. Quiero eliminar la row-? palabras en la propiedad className .

 [ { type: "text", name: "text-1632646960432-0", satir: "1", className: "form-control col-lg-3 row-1" }, { type: "text", name: "text-1632646974512-0", satir: "1", className: "form-control col-lg-6 row-8" } ]

Quiero un resultado como este.

 [ { type: "text", name: "text-1632646960432-0", satir: "1", className: "form-control col-lg-3" }, { type: "text", name: "text-1632646974512-0", satir: "1", className: "form-control col-lg-6" } ]

Cómo puedo hacer eso ? Además, ¿cómo puedo recortar para que no quede espacio al final?

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

0

1) Puede mapear sobre la matriz y luego dividir el nombre de className , filtrarlo y luego unirlo .

 const arr = [ { type: "text", name: "text-1632646960432-0", satir: "1", className: "form-control col-lg-3 row-1", }, { type: "text", name: "text-1632646974512-0", satir: "1", className: "form-control col-lg-6 row-8", }, ]; const result = arr.map((o) => ({ ...o, className: o.className .split(" ") .filter((s) => !s.startsWith("row")) .join(" "), })); console.log(result);
 /* This is not a part of answer. It is just to give the output fill height. So IGNORE IT */ .as-console-wrapper { max-height: 100% !important; top: 0; }

2) También puede usar expresiones regulares /\s*row-\d+/g

ingrese la descripción de la imagen aquí

 const arr = [{ type: "text", name: "text-1632646960432-0", satir: "1", className: "form-control col-lg-3 row-1", }, { type: "text", name: "text-1632646974512-0", satir: "1", className: "row-12 form-control row-6 col-lg-6 row-8", }, ]; const result = arr.map((o) => ({ ...o, className: o.className.replace(/\s*row-\d+/g, "").trim(), })); console.log(result);
 /* This is not a part of answer. It is just to give the output fill height. So IGNORE IT */ .as-console-wrapper { max-height: 100% !important; top: 0; }

o /\s*row-[^\s]+\s*/g

ingrese la descripción de la imagen aquí

 const result = arr.map((o) => ({ ...o, className: o.className.replace(/\s*row-[^\s]+\s*/g, " ").trim(), }));
about 4 years ago · Juan Pablo Isaza Report

0

 const data =[ { type: "text", name: "text-1632646960432-0", satir: "1", className: "form-control col-lg-3 row-1" }, { type: "text", name: "text-1632646974512-0", satir: "1", className: "form-control col-lg-6 row-8" } ]; const results = data.map((item) => { if (item.className.includes('row')) { return { ...item, className: item.className.replace(/row-[0-9]/, '').trim() } } }); console.log(results);

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!