 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Creating an associative array in JavaScript?
You can create an associative array in JavaScript using an array of objects with key and value pair.
Associative arrays are basically objects in JavaScript where indexes are replaced by user defined keys.
Example
var customerDetails= [    {       "customerId":"customer-1",       "customerName":"David",       "customerCountryName":"US"    },    {       "customerId":"customer-2",       "customerName":"Bob",       "customerCountryName":"UK"    },    {       "customerId":"customer-3",       "customerName":"Carol",       "customerCountryName":"AUS"    } ] for(var i=0;i<customerDetails.length;i++){    console.log(customerDetails[i].customerName); } To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo115.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo115.js David Bob Carol
Advertisements
 