Tips for Adding For Loop Value to an Array in JavaScript

Trying to Add For Loop Value to an Array

My Current View

  <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
 <style>    
body {
    font-family: Roboto, sans-serif;
}
#chart {
    max-width: 650px;
    margin: 35px auto;
}
 </style>
  <div id="chart">
  </div>
  <script src="~/Scripts/jquery-1.8.2.min.js"></script>
 <script type="text/javascript">


$(document).ready(function () {
    debugger;
    var cval = "In-Progress";
    $.ajax({
        type: "Post",
        url: '@Url.Action("GetProjectList", "Dashboard")',
        datatype: "Json",
        data: { status: cval },
        success: function (data) {
            debugger;
            console.log(data);
            var catagorydata = new Array();
            var Estimation = new Array();                           
            for (var i = 0; i < data.data.length; i++) {
                catagorydata.push[data.data[i].ProjectID];
                Estimation.push[data.data[i].EstimatedValue];
            }               
            var options = {
                chart: {
                    type: 'line'
                },
                series: [{
                    name: 'sales',
                    data: Estimation
                }],
                xaxis: {
                    categories: catagorydata
                }
            }
            var chart = new ApexCharts(document.querySelector("#chart"), options);
            chart.render();
        }
        })
});
</script>

After receiving 5 values in the data array within the Ajax success function, I am trying to store them in the categorydata and Estimation arrays using a for loop. However, the values are not being stored in the arrays as expected.

                catagorydata.push[data.data[i].ProjectID];
                Estimation.push[data.data[i].EstimatedValue];

The arrays categorydata and Estimation should store the values from the for loop, but they seem to be empty. Assistance in resolving this issue would be highly appreciated.

Answer №1

It appears there is a syntax error in the code. The correct usage for the push method is to use parentheses, not square brackets.

categoryData.push(data.data[i].ProjectID);
Estimate.push(data.data[i].EstimatedValue);

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

There is a potential risk of NextResponse.json file compromising the integrity of JSON

Running nextjs 13.5.3 and implementing an API route handler under /app This route handler mainly fetches data from a CMS and then returns the response. The IDs on the client side are hashed, so one of the functions is to unhash the IDs from a request and ...

Ways to bring GIFs into NextJS

I am currently working on my portfolio website using Nextjs and I would like to incorporate gifs into the site. However, I have been struggling to figure out how to do so. Below is the code that I have been working with: https://i.stack.imgur.com/zjoiD.pn ...

Expanding cards with Material-UI and React seems to be a challenge when using an expander

I've recently integrated a Card component into my project, sourced from material-ui's official website. However, I'm encountering an issue where the CardHeader does not expand upon clicking. This is the structure of my Component : import ...

Adding a unique header to an Ajax CORS request can be achieved by following a few

Searching for a way to include a custom header for Ajax CORS request? Look no further! My server is PHP Lumen and the proxy server is Nginx. The file bootstrap/app.php holds my project configuration details https://i.sstatic.net/zxM7G.png I've come ...

Utilize AngularJS to integrate a service into the router functionality

What is the best way to inject a service into my router so that its JSON result will be accessible throughout the entire application? Router: export default ['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterP ...

Is it possible for PHP to process a multidimensional array being submitted via $_POST along with another field serving as a key in the same form

My web form includes two select fields: "user_id[]" and "equipment_id[]. Here are some key points: I use a Javascript function to duplicate the group of "user_id[]" and "equipment_id[] fields each time I want to add another set. The "user_id[]" field all ...

Having trouble getting the form to submit with jQuery's submitHandler

I am in the process of converting a contact form to AJAX so that I can utilize the success function. Currently, I am encountering an issue where the code is halting at the submitHandler section due to it being undefined. Can anyone identify why my submitHa ...

Node JS Client.query not returning expected results

Currently, I am developing a Web Application that interacts with my PostgreSQL database. However, when I navigate to the main page, it should display the first element from the 'actor' table, but unfortunately, nothing is being retrieved. Below i ...

Managing components within an array

I have this array called match where match[0] = [2014-05-30 15:21:20,781] DEBUG [scheduler-4] (DiamondSchedulerRunner.java:41) Current node is not a manager of:publishEmail in tenant:0 [2014-05-30 15:21:20,781] DEBUG [scheduler-1] (DiamondSchedulerRunne ...

Tips for configuring <link> in NextJs to only activate on a single click

I am currently utilizing the Flickity-React-Component to create a swappable Carousel and I have included NextJs <Link> in its children. However, the issue arises when I click and swap the carousel - after releasing the mouse click, it automatically ...

Is it possible to retrieve 2 arguments within a function in a non-sequential manner?

Let's say there is a function with arguments A, B, C, D, and E. Function(A, B, C, D, E) However, not all arguments are needed all the time. For instance, only A and C are needed in some cases. Currently, I would have to call the function like this: Fu ...

Is there a way to input data into an AngularJS modal?

I'm looking for some assistance : How do I go about loading data into the content of an angular modal? Is there a way to load custom data for a selected item? ............................................................. This is the code ...

The multi update feature is only compatible with $ operators when performing bulk find and update operations in node.js, as indicated by the Mongo

Why am I receiving the error message MongoError: multi update only works with $ operators when attempting to update multiple documents using the bulk find and update method. Things I have tried: var bulk = db.collection('users').initialize ...

Even after being removed from the DOM using Ajax load, JQuery continues to execute

Currently, within my Laravel 5.2 single page application development, I am faced with the following issue. I have an add.blade.php file and an edit.blade.php file, both containing a script with the same class name and id. When I use .load to load add.blade ...

Utilize a jQuery class selector to retrieve the value of a textbox through HTMLHelper

How can I retrieve the value of "StudentID" in a JavaScript function using jQuery? HTML: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Student.Models.vwStudent>>" %> <div class="divClass"> ...

SignalR isn't functioning properly

Setting up Global.asax: void Application_Start(object sender, EventArgs e) { RouteTable.Routes.MapConnection<myconnection>("echo", "echo/{*operation}"); } Creating myconnection.cs: public class myconnection : PersistentConnection { ...

Opt for JavaScript DOM manipulation over jQuery for element selection without depending on jQuery

I am attempting to target a specific element using JavaScript: element = '<div class="c-element js-element">Something Here</div>'; When I try to select this element with the following code: $(element) The result is not as expected ...

What is the best way to generate a new div element when the content exceeds the preset height of the current div?

CSS .page{ width: 275px; hight: 380px; overflow: auto; } HTML <div class="page">dynamic text</div> Is there a way to automatically create new div elements when dynamic text overflows past the fixed height of the init ...

Add a directive on the fly, establish a connection, and display it dynamically

Within my markup, I have a tag element called popup-window which is handled by a specific directive. If I wish to incorporate multiple similar widgets that can be displayed or hidden in various locations, I currently need to include all these elements dire ...

Configuring Firefox settings in Nightwatch

Is there a way to set Firefox preferences in nightwatch? I am trying to achieve the same thing in Java using nightwatch. To set Firefox preferences in nightwatch, you can use the following code snippet: FirefoxProfile profile = new FirefoxProfile(); prof ...