0

What is wrong on my code?

let x = ['hello',1]
let y = [2]
let z = {x:"hello",y:2}
console.log("type of x:",typeof x) // expected array!
console.log("type of y:",typeof y) // expected array!
console.log("type of z:",typeof z) // expected object, ok

Result:

type of x: object
type of y: object
type of z: object
1
  • oops, sorry polluting! I was thinking in JSON primitives instead of Javascript primitives. Commented Feb 17, 2019 at 10:42

1 Answer 1

2

Because JavaScript arrays are objects.

You can check whether a value is an array using the Array.isArray() function.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.