How To Use Strings As Array Indexes Using JavaScript

How To Use Strings As Array Indexes Using JavaScript


  • 2 Feb, 2012

    JavaScript does not have a true hashtable object, but through its wierdness, you can use the array as a hashtable.<script type="text/javascript">var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];for(var i=0; i < days.length; i++) {days[days[i]] = days[i];}document.write("days["Monday"]:"+days["Monday"]);</script>This producesdays["Monday"]:Monday

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.