0
var codeList = [ "ok", "error" ]
var msg = { "status": "ok" }
console.log(msg.status in codeList) // returns false

It seems to be working on my iPad but not my computer. Here's a screenshot on my Chrome 64.0.3282.119, Windows 10 x64, JavaScript V8 6.4.388.40:

Screenshot

imgg
  • 430
  • 6
  • 12

1 Answers1

2

According to documentation:

The in operator returns true if the specified property is in the specified object or its prototype chain.

Use array.includes() instead.

PS: There are a lot of interesting stuff in MDN documentation ;)

Xopoc
  • 254
  • 2
  • 5
  • 1
    As I understand the question he just need to check if status is one of the allowed statuses, so `codeList.includes(msg.status)` should do the work – Xopoc Jan 27 '18 at 15:21