0

I have the following:

var tempList = []
// or
var tempList = new Array()

when I test what it is, it returns an object. How can I initialize it as an array and why is this weird error occurring?

console.log(typeof tempList); // object
WJA
  • 6,676
  • 16
  • 85
  • 152
  • 2
    http://stackoverflow.com/questions/4775722/check-if-object-is-array – Akash Amin May 30 '16 at 10:19
  • If you want an array, then initialize by -- var tempList = new Array(); What you have done, creates a new object only. – T.Shah May 30 '16 at 10:22
  • I am still getting object?? – WJA May 30 '16 at 10:52
  • Maybe it has to be said that I am trying to add objects into the array. Could that be an issue? – WJA May 30 '16 at 10:57
  • Actually http://www.w3schools.com/js/js_arrays.asp , says what I said is wrong and what you did initially was correct. So revert back. Does this 'typeof ' thing really matter? – T.Shah May 30 '16 at 11:17
  • Yes cause the function .push() does not work.. which only holds for arrays. – WJA May 30 '16 at 11:19
  • edit the question and share a little more of the code that causes error. – T.Shah May 30 '16 at 11:35

0 Answers0