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

  • Home
  • SEARCH
  • 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 8299969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:22:12+00:00 2026-06-08T16:22:12+00:00

See codes: <!DOCTYPE html> <meta charset=utf-8> <title>An HTML5 Document</title> <p> <p> <script> var a

  • 0

See codes:

<!DOCTYPE html>
<meta charset="utf-8">
<title>An HTML5 Document</title>
<p>
<p>
<script>
    var a = [1, 2],
        b = [3, 4],
        c = a.concat(b),
        d, e, f, g;

    console.log(c); // No problem

    d = [document.querySelectorAll('p')[0], document.querySelectorAll('p')[1]];
    e = a.concat(d);
    console.log(e); // No problem

    f = document.querySelectorAll('p'); // f = document.getElementsByTagName('p');
    g = a.concat(f);
    console.log(g); // Pretty strange...
</script>

jsFiddle: http://jsfiddle.net/V7gmE

My question is:

c.length is 4. No poblem.
e.length is 4. No poblem.

If I use f = document.querySelectorAll('p'); or f = document.getElementsByTagName('p');, why g.length is ‘3’?

Thank you.

  • 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-08T16:22:14+00:00Added an answer on June 8, 2026 at 4:22 pm

    There is no problem, your third array is just [1, 2, NodeList].querySelectorAll returns a NodeList which in this case contains two elements. In the second example, you specifically take the first and second elements from the NodeList and put them into an array. While NodeLists may seem like arrays, they are not, and when you use the Array.concat method on it, the individual elements are not picked out.

    From MDN:

    NodeList are used very much like arrays and it would be tempting to use Array.prototype methods on them. This is, however, impossible.

    Here is another example that might help get the point across: http://jsfiddle.net/radu/j5gvy/1/

    var a = [1, 2],
        obj = { 0 : '', 1 : ''},
        b = [obj[0], obj[1]];
    
    c = a.concat(obj);
    
    console.log(c.length); // 3
    
    d = a.concat(b);
    
    console.log(d.length); // 4
    

    Just because I define an object that can be accessed like an array does not make it an array.

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

Sidebar

Related Questions

<!DOCTYPE html> <meta charset=utf-8> <title>An HTML5 Document</title> <p>1 <p>2 <p>3 <p>4 <p>5 <p>6 <p>7
Consider the following code: <!DOCTYPE html> <html lang=en> <head> <title>HTML</title> <meta charset=utf-8 /> <style
See my code in action at: http://losthobbit.net/temp/radiogroup.html Here's the code: <!DOCTYPE HTML PUBLIC -//W3C//DTD
Here is my code: <!DOCTYPE html> <html xmlns:fb=https://www.facebook.com/2008/fbml> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8/> <title>New
In the init.rc,i can see the following codes: mkdir /system mkdir /data 0771 system
I see several programmers, including Apple, creating codes where they declare stuff like this:
Why Unicode has several reserved character codes? See the Unicode for two languages- Kannada
This is the source of my simple HTML page (save as .html file): <!DOCTYPE
I've added new meta tags and a different title tag to the head of
I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; if(form.fName.value ==

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.