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".

5
  • 1
    for(var i = 0; i < data.length; i++) { console.log(data[i]); } ? Or console.table(data)? Commented Oct 21, 2014 at 18:07
  • Where are you setting item1, item2, and item3? Commented Oct 21, 2014 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. Commented Oct 21, 2014 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. Commented Oct 21, 2014 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? Commented Oct 21, 2014 at 18:24

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

4 Comments

@ZachLeighton - Exactly.
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.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.