Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:53:01+00:00 2026-06-05T08:53:01+00:00

I saw this script somewhere else, and it will check every single checkboxes: [].forEach.call(document.querySelectorAll(‘input[type=checkbox]’),function(el){

  • 0

I saw this script somewhere else, and it will check every single checkboxes:

[].forEach.call(document.querySelectorAll('input[type="checkbox"]'),function(el){
       el.checked=true;
    }
);​

I know how to use forEach:

[0,1,2].forEach(function(num){
    console.log(num);
});

//0
//1
//2

But now, it is [].forEach, and there is nothing inside. So why does it still work? Why can’t I do this instead?

document.querySelectorAll('input[type="checkbox"]').forEach(function(el){
       el.checked=true;
    }
);​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:53:04+00:00Added an answer on June 5, 2026 at 8:53 am

    JavaScript has first-class functions; that is, they’re treated like objects, and can have their own properties and methods. The built in Function.call method takes a this parameter for the function as its first argument, and the rest of the arguments are passed to the function itself. The array [] is not used, except as a means to access the (less concise, so less used) Array.prototype.forEach method.

    It’s basically a rebinding of Array.forEach for use on something that is not an array, in this case a NodeList. If NodeLists offered a forEach method, then it would be equivalent to, and you may read it as, this:

    document.querySelectorAll('input[type="checkbox"]').forEach(function(el) {
       el.checked = true;
    });​
    

    So, a little more in depth. call will execute a function with a different context. forEach iterates over the context and calls the function it is passed as its argument. So a someFunc.call(thisArg, otherArg) will be executed as if it were in the context of thisArg, like thisArg.someFunc(otherArg). Here’s the simplest example:

    function callMe(something) {
        return something + this;
    }
    
    callMe('Hello'); // Hellonull or Hello[object Window] or something
    callMe.call({}, 'World'); // World[object Object]
    

    apply() works the same way, but you pass an array of arguments as the second argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this in a script I have to work with. What does setting
I saw this script in another thread on stack overflow and tried to play
I saw this beautiful script to add thousands separator to js numbers: function thousandSeparator(n,
I saw this syntax: @helper IncludeJS(string url) { <script src=@url type=text/javascript></script> } Placed on
I saw some jquery code on the Net somewhere, that took this form :
I just saw this in a script mysql_free_result($rawdb); I saw it on a script
I saw code in a project which looks like this: <script src='http://toolbar.wibiya.com/toolbarLoader.php?toolbarId=22800' type='text/javascript'></script> I
I'm creating a script that will take users location from their ip. I saw
WARNING: Dangerous script. Do not run from your command line! Saw this in a
I saw this in jQuery tools in the tooltip script. What is <div/> ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.