What is the process of acquiring JSON and converting it into a JavaScript object array?

Can someone please assist me in converting the JSON generated in Spring Boot into a JavaScript object array? I'm currently facing some difficulties.

https://i.stack.imgur.com/Tx5Ri.png

I've been using XMLHttpRequest and my JS code is as follows:

let evtArray = [];

var request = new XMLHttpRequest(); 

request.onreadystatechange = function () {

   if (request.readyState == 4 && request.status == 200){
      var data = JSON.parse(request.response); 
      console.log(data);

      evtArray = data; 
   }                
}
request.open('GET', '/rest-view/events', true); 
request.send(); 

Thank you,

Murilo

Answer №1

It seems like a simple fix for your issue could be to modify your assignment in the following way:

evtObjt = data._embedded.events; 

By doing this, you will successfully assign the events array to evtObjt. I hope this solution aligns with what you had in mind.

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

An error was encountered in the JSON syntax: Unexpected symbol <

I have encountered a problem with my code that I cannot seem to resolve. Despite the JSON data being successfully sent to the backend and processed correctly, the success function of the call is never triggered. Here is the snippet of my function: Regist ...

Dynamic Wave Effects with jQuery

I'm interested in developing an interactive animation where waves emanate from a central point and trigger similar waves of varying sizes at outer nodes in a circular pattern. After researching, I came across a few libraries: https://github.com/mbos ...

Unable to close Bootstrap 5 modal

All of my modal forms are functioning properly, except for one that I migrated from Bootstrap 4 to Bootstrap 5. This particular modal refuses to close. Neither the Close button (the X at the top of the popup) nor the Cancel button will close the modal. I ...

Vue.js Google Places Autocomplete Plugin

I'm currently working on integrating Google Places Autocomplete with Vue.js. According to the API documentation, the Autocomplete class requires an inputField:HTMLInputElement as its first parameter, like shown in their example: autocomplete = new g ...

Troubles with retrieving Array data for a JavaScript column chart

I am currently developing a Flask app in Python and utilizing render_template to send back 2 arrays, "names" and "deals", to my HTML file. I have confirmed that these arrays are working correctly based on the code snippet below that I tested, which display ...

Checking parameters from two forms that are both associated with the same model in Rails

Recently, a new feature was added to the system - a phone and sim checker. Users are required to input their phone number into the first form. If the phone number is found in the database, a message indicating this is displayed. Otherwise, the form switche ...

What steps can be taken to resolve the error message "t.onSubmit is not a function" that occurs upon form submission?

Upon submitting a form, it should trigger the onSubmit method function. However, an error is being returned instead: TypeError: "t.onSubmit is not a function". I've attempted to address this issue by researching similar problems and solutions provide ...

Retrieve the status of the webpage using the "document.readyState" command within the JMeter WebDriver Sampler with JavaScript

I am relatively new to Selenium and WDS in Jmeter, so I could use some assistance. I'm having trouble writing code that waits for the entire page to load. I came across something like "return document.readyState", but I can't seem to implement it ...

Transmit a JSON array from a controller to a JavaScript variable

I have retrieved a JSON array from a database and it is set up in a controller like this: public ActionResult highlight() { var statesHighlight = db.Jobs .Select(r => r.State); return Json(statesHighlight , JsonRequestBehavi ...

Isolating an array from an object?

I am working with a component that receives props: The data received is logged on the console. What is the best way to extract the array from this object? Before I pass the array to my component, it appears like this: ...

Efficiently sending data to a kintone endpoint with AWS Lambda and Node.js through AJAX

Greetings Stack Overflow community! I need some assistance as I am facing a challenge while trying to interact with an API to insert records into a Kintone App. My approach involves utilizing ajax to communicate with an AWS lambda function built using node ...

Implementing a post request triggered by a button click in Node.js with Express

How can I invoke a controller from a button click event? I tested it in Postman and it works fine, but I'm having trouble calling it from a button on my front-end. I am using Nodemailer and Node Express to send emails. Here is my code. Can someone p ...

Creating metadata for a node/npm module build

Looking for a solution to output JSON with build date and updated minor version number using grunt and requirejs for our application. It seems like this would be a common requirement. Any existing tools that can achieve this? ...

Converting data from Random.org into an integer using JavaScript

I have been working on a small web application to experiment with CSS animations. Although it's functioning, I'm seeking more genuine randomness. To achieve this, I am exploring the use of Random.org. How can I import the output from Random.org i ...

Transferring JSON data back and forth between C# and PHP files

I am trying to send a JSON request from C# to a PHP file in order to save data into a text file. However, the PHP file is unable to read the data. Below is my code: User user = new User { id = 1, name = "Bob", address = "password", phone = "0111111111", a ...

Connecting the v-model in a Vue.js child component to update the parent value

I've encountered an issue with a vue component where I'm trying to link a text input in the child template to a variable in the parent using v-model, but it doesn't seem to be working. How can I make this work? Currently, I am using Vue.js ...

Discovering hidden text within an HTML tag using AJAX and jQuery

Once again, I have a function that retrieves HTML via AJAX, but some of the tags in the HTML received from the AJAX request are styled with display:none;. How can I extract the text within these hidden elements? The code snippet in viewajax.php looks like ...

javascript design pattern - achieving unexpected outcome

In the code snippet provided, the variable a is turning out to be undefined. Are you expecting it to display the parameter value passed in the parent function? function test(a) { return function(a) { console.log('a is : ' + a); // Ou ...

A Smarter Approach to Updating Text Dynamically with JavaScript and Vue

Currently, I am utilizing Vue to dynamically update text by using setInterval() in combination with a data property. The method I have in place is functional, but I am curious if there exists a more efficient way to optimize it. Is the current code as stre ...

Setting the state based on Promise values within a loop

I am currently facing a challenge in my React project where I am using axios to interact with an external API. The goal is to loop through the array of objects retrieved from the API call and utilize the values returned by a separate function within the ...