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

216
Views
Cheerio.js .each() function is returning one large string when used with .find('a').text()

I am using CheerioJS to scrape a list of text from a site. I am correctly finding the text, however something strange is happening when using .each on an array of table rows.

Here is my code

const getTopCollections = async () => {
const response = await axios.get('https://www.nft-stats.com/top-collections/7d')
const $ = cheerio.load(response.data)

const return_data = []

const table = $('table').children('tbody')
table.each((i, element) => {
    let col_name = $(element).find('a').text()
    return_data.push(col_name)
})
console.log(return_data);
return return_data

What I am getting is instead of an array of strings in return_data, I am getting one large string with all of the text in one string, like below:

One big String

I'm guessing it is something to do with how CheerioJS returns data from .each()? I tried saving the result of each .find().text() into its own variable and then inserting that but that didn't fix it.

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

0

As I said in the comments, Cheerio is a weird clone of jQuery and doesn't behave exactly like it. $(element).find('a') finds all the <a> but returns one single Cheerio object. You can iterate the links with

$(element).find('a').each( ..... push etc )

or

$(element).find('a').toArray().forEach( element => ... )
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!