Monday, May 20, 2024
109
rated 0 times [  112] [ 3]  / answers: 1 / hits: 60790  / 13 Years ago, wed, november 23, 2011, 12:00:00

In CoffeeScript, what is the simplest way to check if a key exists in an object?


More From » coffeescript

 Answers
22
key of obj


This compiles to JavaScript's key in obj. (CoffeeScript uses of when referring to keys, and in when referring to array values: val in arr will test whether val is in arr.)



thejh's answer is correct if you want to ignore the object's prototype. Jimmy's answer is correct if you want to ignore keys with a null or undefined value.


[#88939] Tuesday, November 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marinalyssak

Total Points: 637
Total Questions: 101
Total Answers: 94

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;