The Royal Nick Humphrey Global World IT Forum, Home Edition  

Go Back   The Royal Nick Humphrey Global World IT Forum, Home Edition > Webutvikling Forum > Ajax forum > Javascript Forum
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 15-01-08, 16:25
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default javascript hash map implementation

here's my example of a hashmap that i've devised based on this page:
http://www.quirksmode.org/js/associative.html
Code:
<script>
var enToNo = new Object
var noElements = new Array("FORNAVN","ETTERNAVN","ALDER")
var enElements = new Array("FIRST NAME","LAST NAME","AGE")
for(var i = 0; i < enElements.length; i++) {
    enToNo[noElements[i]] = enElements[i];
}
var norwegianWord = 'ETTERNAVN'
alert(enToNo.ETTERNAVN)
alert(enToNo['ETTERNAVN'])
alert(enToNo[norwegianWord])
</script>
so here i've got 2 arrays that i want to convert into a hash map, and it can be used in at least 3 different ways (see the alert examples)
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.

Last edited by Nickleus : 15-01-08 at 16:30.
Reply With Quote
  #2  
Old 25-04-10, 12:12
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default simple static javascript hash map implementation

Code:
<script>
var x = {};
x["a"]= "1";
x["b"]= "2";

alert(x.b);

</script>
i got the idea from this page: http://www.codingforums.com/showpost...60&postcount=9
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +2. The time now is 10:47.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Check out my phrasebook
All rights reserved 2004-2009