keys Summary Returns the keys of the dictionary (optionally filtering the keys to match specified values in the key-value pair). Signatures Click on a signature to select it and view its documentation. public string[] keys() public string[] keys(T value) public string[] keys(T[] values) public string[] keys(bool(T value) policy) Usage public string[] keys() public string[] keys(T value) public string[] keys(T[] values) public string[] keys(bool(T value) policy) Returns An array of the dictionary's keys. An array of matching keys containing the specified value. An array of matching keys containing the specified values. An array of matching keys according to the filter policy. Parameters value The value to search for in the dictionary's key-value pairs. Parameters values The values to search for in the dictionary's key-value pairs. Parameters policy The filter policy. Return true to specify a match and false otherwise. Description Returns all the keys of the dictionary in an array. Returns the keys of the dictionary matching the specified value. Returns the keys of the dictionary matching the specified values. Returns the keys of the dictionary matching the specified value according to the filter policy. Examples Basic Usage 1234567import System; Dictionary<int> empty = {};Dictionary<int> notEmpty = { a: 10, b: 11, c: 12 }; Console.log(empty.keys()); // []Console.log(notEmpty.keys()); // [ "a", "b", "c" ] Get all dictionary keys matching a value 12345import System; Dictionary<bool> enabled = { "server1": true, "server2": false, "server3": true }; Console.log(enabled.keys(true).sort()); // [ "server1", "server3" ] Get all dictionary keys matching a value 12345import System; Dictionary<int> counts = { "eggs": 1, "fish": 2, "milk": 0 }; Console.log(counts.keys([ 1, 2 ]).sort()); // [ "eggs", "fish" ] Get all dictionary keys matching a value 12345import System; Dictionary<int> counts = { "eggs": 1, "fish": 2, "milk": 0 }; Console.log(counts.keys(bool(int count) { return count > 0; }).sort()); // [ "eggs", "fish" ] Share HTML | BBCode | Direct Link