I want to use the map using JavaScript.
I could get the expected output if I use static data.
var tempMap={91: "Live", 41: "Aggr-Pack", 92: "Test", 118: "Group", 115: "Inner Cartons", 122: "SNDC", 102: "Web Service", 82: "EXTERNAL_DEF", 137: "PARTIAL", 72: "Return", 112: "Kit Master Cartons", 46: "SHIP", 134: "VEHICLE_TYPE", 121: "SGTIN", 135: "VEHICLE_ID", 45: "DE-COM", 113: "Bulk Cartons ", 136: "VEHICLE_COLOR", 131: "CARRIER", 52: "Invoice Number", 101: "File", 114: "Product Master Cartons ", 81: "GLN", 42: "Kit", 53: "Shipping Number", 47: "RECEIVE", 111: "Pallet", 133: "SHIPMENT_TYPE", 71: "Sale", 43: "DIS", 116: "Kits", 21: "en", 123: "SSCC", 22: "es", 117: "Products", 44: "COM", 132: "EXPECTED_DELIVERY_DATE", 73: "Transfer", 51: "Purchase Order Number"};
var key=116;
alert(tempMap[key]);
I want to create the dynamic map from response.
The response is
"{91=Live, 41=Aggr-Pack, 92=Test, 118=Group, 115=Inner Cartons, 122=SNDC, 102=Web Service, 82=EXTERNAL_DEF, 137=PARTIAL, 72=Return, 112=Kit Master Cartons, 46=SHIP, 134=VEHICLE_TYPE, 121=SGTIN, 135=VEHICLE_ID, 45=DE-COM, 113=Bulk Cartons , 136=VEHICLE_COLOR, 131=CARRIER, 52=Invoice Number, 101=File, 114=Product Master Cartons , 81=GLN, 42=Kit, 53=Shipping Number, 47=RECEIVE, 111=Pallet, 133=SHIPMENT_TYPE, 71=Sale, 43=DIS, 116=Kits, 21=en, 123=SSCC, 22=es, 117=Products, 44=COM, 132=EXPECTED_DELIVERY_DATE, 73=Transfer, 51=Purchase Order Number}"
I modify the response as given in tempMap data using below javascript code.
var map=(str.replace(/=/gi,"\"= \"").replace(/,/gi,"\",\"").replace(/=/gi,":"));
map="{\""+map.substring(2,(map.length)-1)+"\"}"
But I could not get the output by passing key value. I don’t want to use any other third party to do this.
You have almost got that right.
Adding whitespace characters to second replace
So that later you could execute
or
if you are dealing with browsers that do not support
JSON.