I have extracted an array from a local database and it consists of various entries.
var data = [
['09-08-2017', '62154', 'Approved'],
['09-08-2017', '62155', 'Approved'],
['08-25-2017', '61922', 'Approved'],
['08-25-2017', '61923', 'Approved'],
['08-18-2017', '61949', 'Approved'],
// ...
];
There are approximately 250 different entries in this array. Each entry contains information about the date, job number, and job state.
The first element of each sub-array represents the date of the week of the job, with each week corresponding to the Friday of that week.
The second element is the job number, which is unique for each job but there can be multiple job numbers per week.
The third element represents the job state, which needs to stay associated with the corresponding job number.
My goal is to convert this array into a shifted format where all job numbers and states are grouped together based on the date:
For example:
data['09-08-2017'] = ['62154', 'Approved'], ['62155', 'Approved'];
or possibly as an object:
data['09-08-2017'] = { jobNumber: '62154', jobState: 'Approved' };
I'm unsure how to initialize this new structure or the best way to perform the conversion. Any help or advice would be greatly appreciated. Thank you!
EDIT: I discovered why the initial array was formatted strangely. When transferring an array from PHP to JavaScript, I initially used:
var data = <?php json_encode(print_r($data)); ?> ;
After further research, I changed it to:
var data = <?php echo json_encode(array_values($data)); ?>;
This not only fixed the issue but also provided a more manageable format for my array.