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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:53:21+00:00 2026-05-24T21:53:21+00:00

I wanted to add the elements of an array into another, so I tried

  • 0

I wanted to add the elements of an array into another, so I tried this:

[1,2] + [3,4]

It responded with:

"1,23,4"

What is going on?

  • 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-24T21:53:22+00:00Added an answer on May 24, 2026 at 9:53 pm

    The + operator is not defined for arrays.

    What happens is that Javascript converts arrays into strings and concatenates those.

     

    Update

    Since this question and consequently my answer is getting a lot of attention I felt it would be useful and relevant to have an overview about how the + operator behaves in general also.

    So, here it goes.

    Excluding E4X and implementation-specific stuff, Javascript (as of ES5) has 6 built-in data types:

    1. Undefined
    2. Null
    3. Boolean
    4. Number
    5. String
    6. Object

    Note that although typeof somewhat confusingly returns object for Null and function for callable Objects, Null is actually not an Object and strictly speaking, in specification-conforming Javascript implementations all functions are considered to be Objects.

    That’s right – Javascript has no primitive arrays as such; only instances of an Object called Array with some syntactic sugar to ease the pain.

    Adding more to the confusion, wrapper entities such as new Number(5), new Boolean(true) and new String("abc") are all of object type, not numbers, booleans or strings as one might expect. Nevertheless for arithmetic operators Number and Boolean behave as numbers.

    Easy, huh? With all that out of the way, we can move on to the overview itself.

    Different result types of + by operand types

                || undefined | null   | boolean | number | string | object |
    =========================================================================
     undefined  || number    | number | number  | number | string | string | 
     null       || number    | number | number  | number | string | string | 
     boolean    || number    | number | number  | number | string | string | 
     number     || number    | number | number  | number | string | string | 
     string     || string    | string | string  | string | string | string | 
     object     || string    | string | string  | string | string | string | 
    

    * applies to Chrome13, FF6, Opera11 and IE9. Checking other browsers and versions is left as an exercise for the reader.

    Note: As pointed out by CMS, for certain cases of objects such as Number, Boolean and custom ones the + operator doesn’t necessarily produce a string result. It can vary depending on the implementation of object to primitive conversion. For example var o = { valueOf:function () { return 4; } }; evaluating o + 2; produces 6, a number, evaluating o + '2' produces '42', a string.

    To see how the overview table was generated visit http://jsfiddle.net/1obxuc7m/

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

Sidebar

Related Questions

I am trying to write a predicate to transform an array of elements into
I wanted to add a new property to one of my model (table). Basically
I wanted to add a StackOverflow-style tag input to a blog model of mine.
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Background: i'm using InstantRails 2.0 I wanted to add a new column to an
I have a image button. I wanted to add a text Search on it.
hi i am working with c# and excel-2007... i wanted to add a macro
if i create a html ul. and wanted to dynamically add list items to
If I wanted to badly enough, could I add additional LINQ constructs to LINQ-to-SQL
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>

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.