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

279
Views
Eliminar texto no deseado

Estoy usando reaccionar construyendo un comercio electrónico. Estoy obteniendo datos de la API y la configuración es tan peligrosamente SetInnerHTML en JSX. Necesito eliminar algún texto/palabra de los datos de la API. Agregué una foto con Mark.

¿Cómo elimino eso?

 with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","userid=&aplus&ali_beacon_id=&ali_apache_id=&ali_apache_track=&ali_apache_tracktmp=&dmtrack_c={}&hn=aeproductsourcesite033001217071%2eus44&asid=AQAAAADkyhRi8NcdZwAAAABHROT4NDi+yA==&sidx=Fzc+BeTKFGIAAAAA0uvd1jNUkicntMPM",id="beacon-aplus",src="//assets.alicdn.com/g/alilog/??aplus_plugin_aefront/index.js,mlog/aplus_v2.js") Package included:1 Dress Material:100% Cotton Colors:Beige,Navy,Light Green,Pink Size:S,M,L,XL,2XL,,, Sleeve Length:Full Sleeve Neckline:Square Neck Pattern: Solid Color Length:Ankle Length Thickness:Thin Decoration:Side Pockets Style:Leisure,Bohemian,Retro,Europe Season:Spring,Summer,Autumn Occasion:Family,Holiday,Employment,Travel

Necesito eliminar la primera parte del texto:

ingrese la descripción de la imagen aquí

Imagen: https://prnt.sc/RNl4TG6habCe

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

0

Una opción es que puede usar expresiones regulares con el método split() o con el método match() en su lugar. La expresión regular variará según el método que elija utilizar.

 const data = `with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","userid=&aplus&ali_beacon_id=&ali_apache_id=&ali_apache_track=&ali_apache_tracktmp=&dmtrack_c={}&hn=aeproductsourcesite033001217071%2eus44&asid=AQAAAADkyhRi8NcdZwAAAABHROT4NDi+yA==&sidx=Fzc+BeTKFGIAAAAA0uvd1jNUkicntMPM",id="beacon-aplus",src="//assets.alicdn.com/g/alilog/??aplus_plugin_aefront/index.js,mlog/aplus_v2.js") Package included:1 Dress Material:100% Cotton Colors:Beige,Navy,Light Green,Pink Size:S,M,L,XL,2XL,,, Sleeve Length:Full Sleeve Neckline:Square Neck Pattern: Solid Color Length:Ankle Length Thickness:Thin Decoration:Side Pockets Style:Leisure,Bohemian,Retro,Europe Season:Spring,Summer,Autumn Occasion:Family,Holiday,Employment,Travel`; const removeWithSplit = (data) => data.split(/(\n|\r){2,}/).pop(); const removeWithMatch = (data) => data.match(/(\w\s?)+:.*/g)?.join('\n'); console.log('**WITH SPLIT**'); console.log(removeWithSplit(data), '\n'); console.log('**WITH MATCH**'); console.log(removeWithMatch(data), '\n');

Prima:

Es un fastidio que la API devuelva este texto sin formato. ¿Es posible recuperar JSON en su lugar? Si no, aquí hay una forma de convertir sus resultados en un objeto:

 const data = `with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","userid=&aplus&ali_beacon_id=&ali_apache_id=&ali_apache_track=&ali_apache_tracktmp=&dmtrack_c={}&hn=aeproductsourcesite033001217071%2eus44&asid=AQAAAADkyhRi8NcdZwAAAABHROT4NDi+yA==&sidx=Fzc+BeTKFGIAAAAA0uvd1jNUkicntMPM",id="beacon-aplus",src="//assets.alicdn.com/g/alilog/??aplus_plugin_aefront/index.js,mlog/aplus_v2.js") Package included:1 Dress Material:100% Cotton Colors:Beige,Navy,Light Green,Pink Size:S,M,L,XL,2XL,,, Sleeve Length:Full Sleeve Neckline:Square Neck Pattern: Solid Color Length:Ankle Length Thickness:Thin Decoration:Side Pockets Style:Leisure,Bohemian,Retro,Europe Season:Spring,Summer,Autumn Occasion:Family,Holiday,Employment,Travel`; const removeWithMatch = (data: string) => data.match(/(\w\s?)+:.*/g)?.join('\n'); const resultsToObject = (data: string) => { return data.split('\n').reduce((acc, curr) => { const [key, value] = curr.split(':'); return { ...acc, [key]: value, }; }, {} as Record<string, unknown>); }; console.log(resultsToObject(removeWithMatch(data) as string));
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!