How to loop through key/value object in Javascript? [duplicate]

Beware of properties inherited from the object’s prototype (which could happen if you’re including any libraries on your page, such as older versions of Prototype). You can check for this by using the object’s hasOwnProperty() method. This is generally a good idea when using for…in loops: var user = {}; function setUsers(data) { for (var … Read more

How do I create a keyValue pair (display field) by combining/having two fields in CakePHP 3?

There are various ways to solve this, here’s three of them: Use a callback for the valueField Use a callback and stitch the value together by using values from the results. $query = $this->LocationsUser->Users ->find(‘list’, [ ‘valueField’ => function ($row) { return $row[‘first_name’] . ‘ ‘ . $row[‘last_name’]; } ]) ->where([‘id’ => $id]); See also … Read more

What is difference between const and non const key?

int and const int are two distinct types. std::map<int, float> and std::map<const int, float> are, similarly, different types. The difference between std::map<const int, float> and std::map<int, float> is, to a degree, analogous to the difference between, say, std::map<int, float> and std::map<std::string, float>; you get a fresh map type for each. In the non-const case, the … Read more

What is the difference between a map and a dictionary?

Two terms for the same thing: “Map” is used by Java, C++ “Dictionary” is used by .Net, Python “Associative array” is used by PHP “Map” is the correct mathematical term, but it is avoided because it has a separate meaning in functional programming. Some languages use still other terms (“Object” in Javascript, “Hash” in Ruby, … Read more

for each loop in Objective-C for accessing NSMutable dictionary

for (NSString* key in xyz) { id value = xyz[key]; // do stuff } This works for every class that conforms to the NSFastEnumeration protocol (available on 10.5+ and iOS), though NSDictionary is one of the few collections which lets you enumerate keys instead of values. I suggest you read about fast enumeration in the … Read more

How do you create a dictionary in Java? [closed]

You’ll want a Map<String, String>. Classes that implement the Map interface include (but are not limited to): HashMap LinkedHashMap Hashtable Each is designed/optimized for certain situations (go to their respective docs for more info). HashMap is probably the most common; the go-to default. For example (using a HashMap): Map<String, String> map = new HashMap<String, String>(); … Read more

How to search if dictionary value contains certain string with Python

You can do it like this: #Just an example how the dictionary may look like myDict = {‘age’: [’12’], ‘address’: [’34 Main Street, 212 First Avenue’], ‘firstName’: [‘Alan’, ‘Mary-Ann’], ‘lastName’: [‘Stone’, ‘Lee’]} def search(values, searchFor): for k in values: for v in values[k]: if searchFor in v: return k return None #Checking if string ‘Mary’ … Read more