Below sample code demonstrate on how to read/write dictionary in JS world.
Creating & Adding data to Dictionary
var workOrderDictionary = []; // declare dictionary var companyId1 = 1; var orders1 = [{ ProductId: 10, ProductName: Pen } , {ProductId: 20, ProductName: Eraser} ] workOrderDictionary.push({ key: companyId1, value: orders1 }); var companyId2 = 2; var orders2 = [{ ProductId: 101, ProductName: Lunch-Box } , {ProductId: 20, ProductName: Bottle } ] workOrderDictionary.push({ key: companyId2, value: orders2 });
Reading the data from Dictionary
for (var key in workOrderDictionary) { if (workOrderDictionary.hasOwnProperty(key)) { var orders = workOrderDictionary[key]; } }
Happy Kooding… Hope this helps…!