आप की और वैल्यू पेयर के साथ ऑब्जेक्ट्स के ऐरे का उपयोग करके JavaScript में एसोसिएटिव ऐरे बना सकते हैं।
एसोसिएटिव ऐरे मूल रूप से JavaScript में ऑब्जेक्ट्स होते हैं जहां इंडेक्स यूजर-डिफाइंड कीज़ द्वारा प्रतिस्थापित होते हैं।
उदाहरण
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); }
उपरोक्त प्रोग्राम चलाने के लिए, आपको निम्न कमांड का उपयोग करना होगा:
node fileName.js.
यहां, मेरी फाइल का नाम demo115.js है।
आउटपुट
यह निम्न आउटपुट उत्पन्न करेगा:
PS C:\Users\Amit\JavaScript-code> node demo115.js David Bob Carol