Mapping objects gives back " function map() { [native code] } " .. why

Blue :

So, I am kinda at a lost why I am getting this back, is it because I am bringing the information back as text? I figured regardless it should still be able to go into the p tag.

previous to having the "function map() { [native code] }" return on the websites html, I had [Object, Object] . . . returning to the HTML

index.html :

    <body>
    <p id="results">${results.map}</p>
    <h1>demo</h1>
</body>

Index Route:

 router.get('/', function(req, res, next) {

  scrapper().then(results => {
    console.log("results are ", results);
    res.render('index', {locals: { results }})
  });
});

And then here is the scrapper:

debug = require ('../models/conn');
const puppeteer = require('puppeteer');
const axios = require('axios');
const cheerio = require('cheerio');

async function searchJobs(i) {
   const url = await axios.get('actual url')
    // return fetch(`${url}${i}`)
        .then(response =>  response)

        .then(res => {
            const jobs = [];
            const $ = cheerio.load(res.data);

            $('.result').each((index, element) => {
                const title = $(element).children('.title').text();
                const linkToJob = $(element).children('.title').children('a').attr('href')
                const body = $(element).children('.summary').text();
                jobs[index] = { title, linkToJob, body };
            });
            console.log(jobs);
            return jobs;
            // Prints tbe second child of results class results for that page in console.
            //    console.log($('.result').children().eq(1).text());
        });
        return url;
};
module.exports = searchJobs;

So I have all the information console.loging that I want I am just trying to get it to display on the front-end of the page..

Would love some more help, still new to programming.. only been programming for real for about 3 months now..

Andres Urdaneta :

You are trying to use the map method over the results object. If you iterate over it with the map method, you could do something like this...

<body>
  {results.map(result => { return <p>{result}</p> })}
</body>

This is going to basically create a <p> tag for every result in your results object

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220566&siteId=1