search

Home  >  Q&A  >  body text

typeof something returns an object, not an array

x is an array.

I use console.log(x) and the output result is

[ 'value' ]

But when I check the type of x with console.log(typeof x) it shows as object. why?

P粉659378577P粉659378577394 days ago671

reply all(1)I'll reply

  • P粉277305212

    P粉2773052122023-11-07 09:45:53

    In JS, arrays are objects.

    If you need to test whether a variable is an array:

    if (x.constructor === Array)
       console.log('它是一个数组');

    reply
    0
  • Cancelreply