I want to iterate through an array in javascript inside vue.
I am using apex chart. I want to iterate over data[] according to the number of series(Y_Data_length).
I want to change code
data() {
return {
Y_Data_length: null,
Options: {
xaxis: {
categories: [],
},
},
Series_1: [{
name: "",
data: [],
}],
Series_2: [{
name: "",
data: [],
},
{
name: "",
data: [],
}
],
Series_3: [{
name: "",
data: [],
},
{
name: "",
data: [],
},
{
name: "",
data: [],
}
],
};
},
to form it.
data() {
return {
Y_Data_length: null,
Options: {
xaxis: {
categories: [],
},
},
Series: [
{name:"", data: []}
],
};
},
For reference, Y_Data_length is:
const A = this.chart[0].data
this.Y_Data_length = Object.keys(A).length
I'm not sure to have understand correctly your problem but if you want to get the data array from a specific series, you can use a Vue "computed" to automatically get the correct series.data using Y_Data_length as an array index. Whenever Y_Data_length changes, then this.currentSeriesData will updates too.
export default {
data () {
return {
Y_Data_length: null,
Options: {
xaxis: {
categories: [],
},
},
Series: [
{ name:"series1", data: [] },
{ name:"series2", data: [] },
{ name:"series3", data: [] },
],
};
},
computed: {
currentSeriesData() {
const currentSeries = this.Series[this.Y_Data_length]
if (currentSeries) {
return currentSeries.data
}
return []
}
}
}