Priya
Priya

Reputation: 23

How to Push For Loop Value in array in Javascript

Hi I want to push For Loop Value in Array

My 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>

Here in Ajax Success Function I am getting 5 values in data .Then I used For loop and push the value in array but the value is not storing in array

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

In categorydata and Estimation are arrays and the for loop values is not storing in these ararys.Kindly any one help me to resolve this issue .

Upvotes: 0

Views: 62

Answers (1)

thommu
thommu

Reputation: 86

There seems to be a syntax issue. push is a method and hence should use brackets rather than square brackets.

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

Upvotes: 1

Related Questions