0

I am working on some project.

I have used to javascript array to store and then send these value to server using the ajax call.

I have create array like below:

var item1 = "first value";
var item2 = 123;
var item3 = "last ele ";
var data = [item1, item2, item3];
           console.log(data);

The array elements are the mixture values, means int/string.

Immediate after, I have tried to print array in the console but it says undefined.

Does anyone know to resolve this?

I have also tried to just initialize one array and print it.

But that also not possible.

AS:

var data_array = [1, 2, 3];
console.log(data_array);

Still it say "undefined".

Pankaj Badukale
  • 1,991
  • 2
  • 18
  • 32
  • 1
    `for(var i = 0; i < data.length; i++) { console.log(data[i]); }` ? Or `console.table(data)`? – George Stocker Oct 21 '14 at 18:07
  • Where are you setting `item1`, `item2`, and `item3`? – Esteban Felix Oct 21 '14 at 18:07
  • 1
    Even if the values of `item1`/`item2`/`item3` are undefined, `console.log(data)` will not print "undefined". The console *may* print "undefined" indicating the return value of the `console.log` though. – user229044 Oct 21 '14 at 18:08
  • I have checked the element values, It going to be printed in console. I have updated my question can you please have look. – Pankaj Badukale Oct 21 '14 at 18:10
  • Just tried in ie10 with the console open and your code above runs correctly. What if you try alert(data_array) instead? – Will Oct 21 '14 at 18:24

1 Answers1

1

There's a good chance it's not your array that's undefined, but the value of console.log (or console) that's undefined. As I recall, IE10 doesn't define console until you've actually opened up your dev tools. So if you try to run a page that writes to console.log without having your dev tools open, you've got a good chance of running into an undefined error.

What precise error are you seeing? Can you provide a screenshot?

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • 1
    http://stackoverflow.com/questions/3767924/js-override-console-log-if-not-defined – Zach Leighton Oct 21 '14 at 18:24
  • @ZachLeighton - Exactly. – Ken Smith Oct 21 '14 at 18:25
  • My browser(IE) dev tool is opened. It print the other console message just don't know array does not getting print like other browser. Same script working properly in other browser. – Pankaj Badukale Oct 21 '14 at 18:29
  • What happens if you open up your dev tools and just type `console.log([1,2,3])`? I see it print first `undefined` (because it's printing the return value of `console.log`, which is undefined), and then it shows the array values. – Ken Smith Oct 21 '14 at 18:32