I have a problem with removing the first element of an array.
To be short, this is how my array looks like if I show it in console:
(11) [Array(4), Array(4), Array(4), Array(4), Array(4), Array(4), Array(4), Array(4), Array(4), Array(4), Array(4)]
0 : (4) ["2017-09-20T16:00:00-07:00", 188.125, 0, 1]
1 : (4) ["2017-09-20T17:00:00-07:00", 123.125, 0, 1]
2 : (4) ["2017-09-20T18:00:00-07:00", 114.25, 0, 1]
3 : (4) ["2017-09-20T19:00:00-07:00", 115, 0, 1]
4 : (4) ["2017-09-20T20:00:00-07:00", 113.25, 0, 1]
5 : (4) ["2017-09-20T21:00:00-07:00", 115.625, 0, 1]
6 : (4) ["2017-09-20T22:00:00-07:00", 114.75, 0, 1]
7 : (4) ["2017-09-20T23:00:00-07:00", 114, 0, 1]
8 : (4) ["2017-09-21T00:00:00-07:00", 112.625, 0, 1]
9 : (4) ["2017-09-21T01:00:00-07:00", 108.375, 0, 1]
10 : (4) ["2017-09-21T02:00:00-07:00", 111.125, 0, 1]
length : 11
__proto__ : Array(0)
I want to remove the first one, 0, I tried using .shift() but didn't work.
Like my array is called myArray.data and I tried myArray.data.shift() and I get this error message:
TypeError: Cannot read property '0' of undefined
at bundle.js:1554
at Function._.map._.collect (vendor.js:11761)
at renderChart (bundle.js:1547)
at bundle.js:1611
at Scope.$digest (vendor.js:34716)
at Scope.$apply (vendor.js:34986)
at bundle.js:259
at vendor.js:14387
at _fulfilled (vendor.js:13992)
at self.promiseDispatch.done (vendor.js:14021)
Any ideas how to solve this?
Later edit:
The code is inside a chart generation function, this is the whole snippet:
data: {
type: chartType,
columns: [
['x'].concat(_.map(myArray.data, function (dataPoint) {
const x = (myArray.data).shift();
console.log(myArray.data);
console.log(x);
return moment(dataPoint[0]).valueOf();
})),
['Expected'].concat(_.map(myArray.data, function (dataPoint) {
return dataPoint[1];
})),
['Actual'].concat(_.map(myArray.data, function (dataPoint) {
return dataPoint[1];
}))
],
x: 'x'
},
shiftshouldn't give you this error I think.dataPoint[0]