Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Testing</title>
- <script type="text/javascript">
- var data = ["whole", "2020-04-16", "2020-04-17","parking_a", "2020-04-16", "2020-04-16", "parking_b", "2020-04-17", "2020-04-17"];
- var chunkData = function(array, size) {
- // Check if array exists
- if(!array) {
- return [];
- }
- // Create first chunk
- var firstChunk = array.slice(0, size);
- if(!firstChunk.length) {
- return array;
- }
- return [firstChunk].concat(chunkData(array.slice(size, array.length), size));
- }
- var getData = chunkData(data, 3);
- var restructureData = [];
- getData.forEach(function(item, index) {
- restructureData[index] = {
- id: item[0],
- start_date: item[1],
- end_date: item[2]
- };
- });
- console.log('Array');
- console.log(restructureData);
- console.log(' ');
- console.log('JSON')
- console.log(JSON.stringify(restructureData));
- </script>
- </head>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement