in Summary Checks if an object/container has a property or if an index is in an array. Syntax property in object Parameters property The name of a property to check for. object Any valid JavaScript object or JS++ container. Description The in operator returns true if the property exists in an object or container and false otherwise. For arrays, the in operator returns true if a given index ("property") is in the array. For dictionaries, the in operator returns true if the dictionary contains the specified key ("property"). Examples Using 'in' operator with System.Dictionary 123456789import System; Dictionary<int> names = {{ "George": 25, "Paul": 26, "David": 40}}; Console.log("Paul" in names); // true Using 'in' operator with arrays 123456import System; string[] names = [ "George", "Paul", "David" ]; Console.log(0 in names); // trueConsole.log(5 in names); // false Using 'in' operator on externals 123456789var a = [ 1, 2, 3 ];"0" in a; // true, "0" is index 0 here var a = { b: 1 };"b" in a; // true function a() {}a.b = 1;"b" in a; // true Incorrect usage of 'in' 12345678var cart = [ "book", "toaster", "toy" ]; bool i0, i2, i3, ibook; i0 = 0 in cart; // truei2 = 2 in cart; // truei3 = 3 in cart; // falseibook = "book" in cart; // false. 'in' refers to element number, not contents See Also for...in foreach Share HTML | BBCode | Direct Link