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

102
Views
.each loop is not working in my jQuery code

The code below is written to hide the "IN STOCK" phrase on certain vendors' product pages. I noticed the loop itself isn't running when I used console.log. Could you please help correct the code?

function runPmmCustomAllPagesJs($) {
    // This function is called from argento-custom.js once dom is ready and jQuery obect is available.
    // $ has the jQuery object.

    var docloch = document.location.href,
        scree = [screen.availWidth, screen.availHeight],
        thisVal = "",
        tAlign = "left",
        afterwhat = "h3",
        df,
        hide_inStock= [':"JV', ':"KE', ':"MB', ':"WD'],
        doc_text=$(document).text(),
        v_code;
        
        
    // hides the "IN STOCK" phrase on certain vendors' product pages
    $(hide_inStock).each(function(v_code){
        console.log('v_code: ' + v_code);
        if (doc_text.indexOf(v_code)>1){
            $(".stock").hide();
            return false;
        }
    });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When false is returned from the predicate, the iteration is ended prematurely. Return something else or even nothing if you want it to get to the end.

Also, remember that the first argument passed to .each is the index.

$([1, 2, 3]).each((_index, value) => {
    console.log(value);

    if (value === 2) {
        return false;
    }
});
// 1
// 2
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!