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

189
Views
Leer un archivo de texto línea por línea en una extensión de Chrome

Estoy trabajando en una extensión de Google Chrome que tomará una dirección de correo electrónico y recorrerá una lista blanca para ver si obtenemos una coincidencia. Estoy trabajando con funciones dentro de un script content.js y tengo un archivo whitelist.txt dentro del mismo directorio que manifest.json . Estoy intentando iterar a través de cada línea del archivo whitelist.txt pero está resultando bastante difícil con JavaScript. Puedo leer el archivo y puedo registrarlo en la consola; sin embargo, cuando intento iterar a través de cada línea, lo dividirá letra por letra. ¿Cómo haría para iterar el archivo línea por línea?

 content.js const url = chrome.runtime.getURL('whitelist.txt'); fetch(url).then(function(response) { return response.text().then(function(text) { for (let i = 1; i < text.length; i++) { /* Logic for seeing if email is on list */ console.log(text[i]); /* Outputs the file line by line letter by letter. */ return (email.test(text[i])); } //console.log(text); /* Outputs the entire txt file to the console */ }); });
 whitelist.txt ... yahoo.com yahoo.com.ar yahoo.com.au yahoo.com.br yahoo.com.cn yahoo.com.hk yahoo.com.is yahoo.com.mx yahoo.com.ph yahoo.com.ru yahoo.com.sg yahoo.de yahoo.dk yahoo.es yahoo.fr yahoo.ie yahoo.in ...
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El text que se devuelve es una cadena. Puede separarlo palabra por palabra con la función split() .

 const words = text.split("\n"); //array of words
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!