I want to send data(array of objects) from java servlet to JavaScript.
Data should be in below format:
[
{
deviceId: 'TestDevice_001',
deviceName: 'D_01',
count: 1,
expirationDate: '05/31/2021',
},
{
deviceId: 'TestDevice_002',
deviceName: 'D_02',
Count: 5,
expirationDate: '11/23/2024',
},
{
deviceId: 'TestDevice_003',
deviceName: 'D_03',
Count: 4,
expirationDate: '07/12/2022',
},
]
I tried this by taking multiple arrays:
arr = ["deviceId", "deviceName", "count", "expirationDate"]
and insert records in extra arrays like:
arr1 = ["TestDevice_001", "D_01", 1, "05/31/2021"]
arr2 = ["TestDevice_002", "D_02", 5, "11/23/2024"]
arr3 = same above format for 3rd record
After getting this data, tried to use hash map and other methods but failed. Also, above approach is really bad to use as I am creating multiple arrays for each records because if have to insert 50 records then have to create 50 arrays.
Can someone please help me here, what approach and how to convert the data into array of objects in above format in java servlet and send to JavaScript.