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

133
Views
Function inside JavaScript Array map not returning promises

Trying to process all results of an array nodes from a function but nothing was added to promises.

const promises = nodes.map(localModelScan);

function localModelScan(node) {
    let text = node.textContent;
    model.then(function (res) {
        if(res.check(node.text) > 0.3) return node;
    }).catch((error) => {
        console.error('Error:', error);
    });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to have return model; at the end of your localModelScan function, otherwise promises will just be an array full of undefined.

const promises = nodes.map(localModelScan);

function localModelScan(node) {
    let text = node.textContent;
    return model.then(function (res) {
        if(res.check(node.text) > 0.3) return node;
    }).catch((error) => {
        console.error('Error:', error);
    });
}

Alternatively, you can write this as an arrow function:

const localModelScan = (node) => model.then((res) => {
        if(res.check(node.text) > 0.3) return node;
    }).catch((error) => {
        console.error('Error:', error);
    });

const promises = nodes.map(localModelScan);
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!