
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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