0

I have the following JavaScript code :

 function dox( )
         {    
          d= [1, 2, 3] + [1,2,3]     ;

          d.map(function(value) {return parseInt(value)});
          document.writeln(d );

      }

and I got the following error :

Uncaught TypeError: undefined is not a function.

I spent a lot of time to solve this bug but I could not ,

Could somebody explain me what is the problem !?

Thanks

Micha agus
  • 531
  • 2
  • 5
  • 12
  • Many things went wrong in so little code... Try reading some JavaScript tutorials first. – elclanrs May 04 '14 at 00:56
  • possible duplicate of [Why does \[1,2\] + \[3,4\] = "1,23,4" in JavaScript?](http://stackoverflow.com/questions/7124884/why-does-1-2-3-4-1-23-4-in-javascript) – Qantas 94 Heavy May 04 '14 at 07:14

1 Answers1

2
d= [1, 2, 3] + [1,2,3]  

This does not concatenate arrays, you need:

var someVar = array1.concat(array2);

If you use + on arrays they will get coerced to strings then concatenated so you actually get a string containing "1,2,31,2,3"

Strings don't have a map function and that's why you get the error

You probably need to put var in front of that d variable so it doesn't leak into the global scope.

Metalstorm
  • 2,940
  • 3
  • 26
  • 22