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 6651381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:00:16+00:00 2026-05-26T01:00:16+00:00

Was messing around with some array stuff earlier and discovered a very peculiar caveat

  • 0

Was messing around with some array stuff earlier and discovered a very peculiar caveat

consider this code:

[1,2,3].map(function(el) { return el * 2}).push(4*2).join(" ");

In writing it, I expected to get: 2, 4, 6, 8

instead, it threw an exception. in investigating further, the .push returns the adjusted .length of the passed array:

[1,2,3].map(function(el) { return el * 2}).push(4*2);
>>> 4

[1,2,3,4].map(function(el) { return el * 2}).push("hi");
>>> 5

and typeof is number, so the .join throws as it’s not in the number proto.

it seems you can pass on / chain any other array methods but not push. though this is not a problem and it works if you pass on the result into a variable, why is breaking as is and why is the length property being returned here?

this works fine…

var foo = [1,2,3,4].map(function(el) { return el * 2});
foo.push(5*2);
console.log(foo); 
>>> [2, 4, 6, 8, 10]; 

probably another wtfjs moment…

  • 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-05-26T01:00:16+00:00Added an answer on May 26, 2026 at 1:00 am

    Why is the length property being returned here?

    It is defined in the specification:

    The arguments are appended to the end of the array, in the order in which they appear. The new length of the array is returned as the result of the call.

     

    Why is breaking as is?

    Well, you answered this already yourself: .push returns the new length and .join is not defined for numbers.

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

Sidebar

Related Questions

I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00
I am currently messing around with some stuff for an idea for a site
The situation is that I've spent some time messing around with some experimental code.
I have been messing around with writing some stored procedures in .NET code with
I'm messing around with some jQuery stuff for a mockup and noticed some odd
I'm messing around with some audio stuff and the algorithm I'm trying to implement
I'm messing around with some interprocess communication stuff and I am curious if it's
I'm messing around with some windows functions using p/invoke. Occasionally, I get an error
I have finally started messing around with creating some apps that work with RESTful
I was messing around with RhinoMocks this morning and couldn't run my tests because

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.