I possess an array with a specific structure that I wish to substitute the keys as demonstrated below

The data array is currently structured in this way. I have attempted various methods but have not been able to find a suitable solution.

I need to send the JSON below via an AJAX request, however, I do not want the keys 0 and 1 in both child arrays.

[scheduleDetails] => Array
    (
        [2] => Array
            (
                [Wednesday] => Array
                    (
                        [0] => Array
                            (
                                [startTime] => Array
                                    (
                                        [0] => 00:00
                                        [1] => 12:00
                                    )

                            )

                        [1] => Array
                            (
                                [endTime] => Array
                                    (
                                        [0] => 12:00
                                        [1] => 07:40
                                    )

                            )

                    )

            )
)

What I am aiming for is as follows:

             [scheduleDetails] => Array
            (

                [Wednesday] => Array
                    (

                                [startTime] => Array
                                    (
                                        [0] => 00:00
                                        [1] => 12:00
                                    )


                                [endTime] => Array
                                    (
                                        [0] => 12:00
                                        [1] => 07:40
                                    )



                    )

            )

Can anyone suggest the best approach to achieve this, either in regular JavaScript or jQuery?

       "scheduleDetails":[
        {"Friday":[{"startTime":["09:00","15:00"]},{"endTime":["13:00","21:00"]}]}],

For example:

     "scheduleDetails":[
      "Friday":["startTime":["09:00","15:00"]},{"endTime":["13:00","21:00"]]],

Answer №1

 "timetableInfo":[
      "Friday":[{"start":["09:00","15:00"]},{"end":["13:00","21:00"]}]],

Make sure to properly open and close your arrays.

[,] -> array object
{}-> object

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

File appears to be empty after passing through ajax request

I have encountered an issue with my ajax submit function. When I submit the function, worklogdetailsidschedule and shift_schedule are successfully inserted into the database. However, the filename_schedule, which is a file, appears empty in the database. ...

Struggling with developing a straightforward application with Angular-Material

My goal is to develop an application that utilizes the Angular Material navigation bar, as showcased in this example. Being relatively new to AngularJS, I'm facing an issue where my app loads but only displays a blank page. Below is the code snippet ...

Error message: A state has not been defined within the onload function

I'm facing an issue where I am attempting to assign a data URL of an image to a state in Vue.js, but it is not getting assigned properly. After converting a blob URL to a data URL, the state does not contain the correct data URL. While the imgSrc doe ...

The NPM Install process seems to be skipping certain files that were successfully installed in the past

When I first installed NPM Install in a folder, it created multiple folders and files: node_modules public src .DS_Store package.json package-lock.json webpack.config.js After that, npm start functioned perfectly. Now, as I embark on a new project for th ...

Choosing and Duplicating Text in Angular

I'm attempting to give the user the ability to select a paragraph and copy it by clicking a button. However, my current code is not working as expected. I initially tried importing directives but encountered errors, prompting me to try a different met ...

Tips for unit testing an Angular Service that is primarily responsible for redirecting to an external page from the application

My service is responsible for redirecting to a separate login page since we are implementing login as a service. function redirectToMembership() { var returnURL = $location.host(); returnURL+="/#/Authorization"; $window.location.href=Environme ...

The 'export '__platform_browser_private__' could not be located within the '@angular/platform-browser' module

I have encountered an issue while developing an angular application. Upon running ng serve, I am receiving the following error in ERROR in ./node_modules/@angular/http/src/backends/xhr_backend.js 204:40-68: "export 'platform_browser_private' w ...

Angular - Detecting Scroll Events on Page Scrolling Only

I am currently working on implementing a "show more" feature and need to monitor the scroll event for this purpose. The code I am using is: window.addEventListener('scroll', this.scroll, true); Here is the scroll function: scroll = (event: any) ...

Synchronize MySQL database structure with HTML5 local storage to enable querying

After researching HTML5 local storage, I am considering mirroring a MySQL database's structure for use in an application that requires a large amount of data for a single user. Why would I want to do this? As a web game developer in my spare time, I ...

Innovative application transforms rigid input with dynamic hyphens

I am currently working on an input field specifically designed for Social Security Numbers (SSNs). My aim is to have an input with pre-placed hyphens, allowing the user to simply enter their 9-digit SSN while the numbers automatically space themselves arou ...

Attempting to transform UNIX Epoch time to regular date format extracted from JSON<Object>

Trying to convert Unix epoch time into a standard date format using JSON. Snippet from the JSON file: {"success":true,"lastUpdated":1621365664405 An implementation is as follows: import requests import json from datetime import dateti ...

Transitioning from mui version 4 to version 5 leads to an error message: "TypeError: Cannot access 'keyboardDate' properties of undefined"

After updating from MUI v4 to version v5, I encountered failing tests with the following error: TypeError: Cannot read properties of undefined (reading 'keyboardDate') 17 | it("should render correctly without any errors", () =& ...

JavaScript array as a reliable data storage solution

This is my unique jsp code where I am attempting to push certain data into a JavaScript array. <% int proListSize = proList.size(); ProfileDAO proDAO = null; for(int i = 0, j=1; i < proListSize; i++){ proDAO = ( ...

Is there a way to execute an SQL query using ajax?

I recently came across an interesting problem involving passing an SQL query through to an ajax file. let qry = mysqli_query($this->con,"SELECT * FROM products"); To ensure proper containment, I embedded the variable within HTML using the following co ...

Looking for a list of events in Express.js?

I've been searching through the official documentation, but I couldn't find a list of events for express. Does anyone know if there's something like 'route-matched' so that I can use app.on('route-matched', () => {})? ...

Exceeded server capacity while attempting to extract pricing information from a search bar

Thanks to some guidance from the Stackoverflow community, I successfully developed a scraper that retrieves a list of part numbers along with their respective prices. Here is an example format of the data retrieved: part1 price1 part2 price2 ... .. ...

Is it possible for Susy to output a pixel-based span?

As a newbie to Susy, I hope you don't mind if I ask a seemingly silly question... I'm trying to figure out how to calculate responsive padding within a Susy grid. The standard formula is: (target / context) x 100. Is there a way for Susy to pr ...

What is the best way to implement a delay before calling the owlCarousel function?

Is there a way to delay calling the owlCarousel function for 5 seconds? I attempted the following: $(document).ready(function(){ setInterval(function(){ $(".demo-slide").owlCarousel(); },5000); }); However, I encountered ...

The webpage contains duplicate ID attribute value "x" that has been identified

In my Angular 7 project, three components (a, b, c) all use an input element with the same id of "x". However, component b has 4 input elements all using the id "x" as well. This poses Accessibility Issues as ids must be unique. The test cases utilize &apo ...

Transmit data in the form of a buffer

const response = await client.render(data); const Writable = require('stream').Writable; var buffer = []; const myWritableStream = new Writable({ write(chunk, encoding, callback) { ...