`prop in obj`
JS ⟩ statement ⟩ expression ⟩ operator ⟩ relational ⟩ in
// ⭐️ check if `prop` is property of `obj` (including inherited) prop in obj // ⭐️ prop: string-convertable expression
🌟 table of operators
⚖️ for-in vs. for-of vs. in
replit: "in" operator
let point = {x: 1, y: 2}; let array = [1, 2, 3]; 'x' in point, // true 'z' in point, // false 'toString' in point, // true (inherited) '0' in array, // true 1 in array, // true (1 -> '1') 3 in array, // false (3 -> '3', no such prop) 'toString' in array, // true (inherited)
JavaScript: The Definitive Guide ⟩ 4.9.3 The in Operator
in operator
Last updated 2 years ago