Tagged Questions

An associative array is an abstract data type composed of a collection of unique keys mapped to a collection of values.

learn more… | top users | synonyms

246
votes
3answers
114k views

Checking if an associative array key exists in Javascript

How do I check if a particular key exists in a Javascript associative array? If a key doesn't exist and I try to access it, will it return false? Or throw an error?
127
votes
7answers
67k views

How do I remove objects from a javascript associative array?

Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"] = "Smith"; myArray["age"] = 25; Now if I wanted to remove "lastname"?....is there some ...
48
votes
6answers
45k views

In PHP, how do you change the key of an array element?

I have an associative array in the form key => value where key is a numerical value, however it is not a sequential numerical value. The key is actually an ID number and the value is a count. This ...
47
votes
8answers
91k views

Dynamically creating keys in javascript associative array

Simple, quick, question. How can I create dynamically create keys in javascript associative arrays? All the doc I've found so far is to update keys that are already created: arr['key'] = val; I ...
42
votes
14answers
28k views

Java associative-array

How to create and fetch associative array in Java, like this in php? $arr[0]['name'] = 'demo'; $arr[0]['fname'] = 'fdemo'; $arr[1]['name'] = 'test'; $arr[1]['fname'] = 'fname';
38
votes
10answers
35k views

How to define hash tables in bash?

Just what title says. I am surprised by insufficiency of results in Google search for this question! What I want to is the equivalent of Python dictionaries but in bash (and hence, should work across ...
29
votes
11answers
30k views

Associative arrays in Shell scripts

We required a script that simulates Associative arrays or Map like data structure for Shell Scripting, any body?
25
votes
2answers
7k views

How to iterate over associative array in bash

Based on an assoziative array in a bash script I need to iterate over it to get key & value. #!/bin/bash declare -A array array[foo]=bar array[bar]=foo I actually don't understand how to get ...
17
votes
5answers
24k views

Fastest way to implode an associative array with keys

I'm looking for a fast way to turn an associative array in to a string. Typical structure would be like a URL query string but with customizable separators so I can use '&' for xhtml links or ...
16
votes
4answers
10k views

How to determine if an associative array has a key?

In ActionScript 3, is there any convenient way of determining if an associative array (dictionary) has a particular key? I need to perform additional logic if the key is missing. I could catch the ...
14
votes
3answers
4k views

PHP prepend associative array with literal keys?

Is it possible to prepend an associative array with literal key=>value pairs? I know that array_unshift() works with numerical keys, but I'm hoping for something that will work with literal keys. As ...
13
votes
5answers
7k views

Hash tables VS associative arrays [PHP]

Recently I have read about hash-tables in a very famous book "Introduction to Algorithms". I haven't used them in any real applications yet, but want to. But I don't know how to start. Can anyone give ...
12
votes
4answers
34k views

How to sort a date array in PHP

I have an array in this format: Array ( [0] => Array ( [28th February, 2009] => 'bla' ) [1] => Array ( [19th March, 2009] => 'bla' ...
12
votes
11answers
1k views

How to add an array value to the middle of an associative array?

Lets say I have this array: $array = array('a'=>1,'z'=>2,'d'=>4); Later in the script, I want to add the value 'c'=>3 before 'z'. How can I do this? EDIT: Yes, the order is important. ...
12
votes
3answers
10k views

JavaScript associative array to JSON

How can I convert a JavaScript associative array into JSON? I have tried the following: var AssocArray = new Array(); AssocArray["a"] = "The letter A" console.log("a = " + AssocArray["a"]); // ...

1 2 3 4 5 41
15 30 50 per page