Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

scyre's avatar
Level 3

Filtering data returned by axios after a specific array

Hi Fellows.

I'm trying to filter my returned axios data, which looks like this:

{
    "data": {
        "9491931395853: {
            "labels": [
                "2022-11-07 00:00:00",
                "2022-11-09 00:00:00",
                "2022-11-10 00:00:00",
     			"2022-11-12 00:00:00",
            ],
            "plots": [
                34,
                0,
                30,
                66
            ]
        },

I need to get access to the plots in this one, and normally it should work by iterating over it, but it doesn't. I do not know what i'm doing wrong. I need those plots to implement them in a standard line chart (eCharts in an Vue Component).

the "9491931395853" is variable. Stands for a ProductID which comes with the fetch from the API. Thought it should work with Array.prototype.filter() like

const plots = Object.values(response.data).filter(data => data.hasOwnProperty("plots"));

Could you guys help me out here?

0 likes
2 replies
MohamedTammam's avatar
const plots = [];
Object.values(response.data).forEach(d => { 
    if (d.hasOwnProperty('plots')) {
        plots .push(...d.plots);
    }
});
scyre's avatar
Level 3

I need some context to be fair.


  computed: {
    chartOptions() {
      const series = [
        {
          data: [this.fetchedChartData],
          type: 'line',
          symbol: 'none',
          smooth: 0.1,
          areaStyle: {
            color: 'rgba(20, 137, 253, 0.1)',
          },
          lineStyle: { color: '#1489FD', width: 1.5 },
        },
      ];

Want to push that data into the fetchedChartData (data) in this const. for eCharts.

Please or to participate in this conversation.