366
votes
3answers
161k 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?
173
votes
7answers
94k 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 ...
69
votes
8answers
130k views

Dynamically creating keys in javascript associative array

Simple, quick, question. How can I 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 have a ...
15
votes
3answers
20k 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"]); // ...
14
votes
5answers
23k views

Multi-dimensional associative arrays in javascript

There is the following query results: (key1 and key2 could be any text) id key1 key2 value 1 fred apple 2 2 mary orange 10 3 fred banana 7 4 fred orange ...
12
votes
4answers
179 views

How does JavaScript [] really work?

I'm writing a JavaScript interpreter for extremely resource-constrained embedded devices (http://www.espruino.com), and every time I think I have implemented some bit of JavaScript correctly I realise ...
7
votes
5answers
5k views

Javascript: Using integer as key in associative array?

When I create a new javascript array, and use an integer as a key, each element of that array up to the integer is created as undefined. for example: var test = new Array(); test[2300] = 'Some ...
6
votes
7answers
6k views

Google Chrome: JavaScript associative arrays, evaluated out of sequence

Ok, so on a web page, I've got a JavaScript object which I'm using as an associative array. This exists statically in a script block when the page loads: var salesWeeks = { "200911" : ["11 / ...
6
votes
1answer
15k views

Javascript: Checking if an object has no properties or if a map/associative-array is empty [duplicate]

Possible Duplicate: How do I test for an empty Javascript object from JSON? Is there an easy way to check if an object has no properties, in Javascript? Or in other words, an easy way to ...
6
votes
4answers
6k views

Can you convert C# dictionary to Javascript associative array using asp.net mvc Json()

I recently asked this question, but after some of the responses and some research, i wanted to change what i was actually asking. i have seen a number of blog posts about sending associative arrays ...
6
votes
6answers
3k views

How are javascript arrays implemented?

Namely, how does the following code: var sup = new Array(5); sup[0] = 'z3ero'; sup[1] = 'o3ne'; sup[4] = 'f3our'; document.write(sup.length + "<br />"); output '5' for the length, when all ...
5
votes
3answers
1k views

Why do associative arrays don't work in localStorage[“”]?

For example I have the following code: localStorage["screenshots"] = new Array(); localStorage["screenshots"]["a"] = 9; alert(localStorage["screenshots"]["a"]); Arr = new Array(); ...
5
votes
4answers
779 views

What's the difference between objects and associated array in javascript?

The Confusing discussion In this question, there is a discussion on the concepts of associated array and object in javaScript which I got a bit confused. In this example code: var check = { ...
5
votes
2answers
172 views

Using an associative array as a variable name? - javascript

I was looking through some code from a firefox extension (here: https://github.com/mozilla/prospector/blob/master/oneLiner/bootstrap.js#L34 ) and I saw something I'd never seen before in javascript. ...
5
votes
3answers
709 views

JavaScript: memory/efficiency of associative arrays?

I am building a tree-like data structure out of associative arrays. Each key is 1-2 characters. Keys are unique to their respective level. There will be no more than 40 keys on the root level and no ...

1 2 3 4 5 9
15 30 50 per page