I currently have a problem in deleting entries from an associative array in JS.
I tried this:
myArray['key'] = value;
myArray['key1'] = value1;
...
delete myArray['key'];
But I get following results in my application:
[ undefined, { key1: 'value1', key2: 'value2' }, undefined,
{ key1: 'value1', key2: 'value2' }, undefined, undefined ]
How can I delete the whole entry, key and value? I found the method splice() but I think it uses a different index. I wasn’t able to delete the entries I want by passing the key to splice().
It seems you are mixing arrays and objects. Associative arrays should be realized with objects:
It is a bit confusing though because in your output, the objects don’t have
keyanymore (so it worked), but the array containing those objects as undefined values. I cannot see howdelete myArray['key'];is related to your output and which variable now contains which value (please clarify).But it looks like you did something like:
This will initialize the array with 6
undefinedvalues (sort of) and then set the second and forth value to something else.If you want to use that “array” as associative array, you should declare it as object too:
Please post more code if you need a better answer.
Update: Yes, you should declare
displayedWidgetsas object: