0

I have a function like below in jQuery

Ranges is declared for 3d array. This is getting inserted properly. average is 2d array.

var ranges = [];
var averages = [];
$.each(data, function(i, item){
    alert([item.xAxisTime, item.upperBound, item.lowerBound]);
    ranges.push([item.xAxisTime, item.upperBound, item.lowerBound]);
    averages.push([item.xAxisTime, item.yAxisValue]);
});

i want to produce result like below

2d array:

averages = [
            [1246406400000, 21.5],
            [1246492800000, 22.1],
            [1246579200000, 23],
            [1246665600000, 23.8]];

3d array

ranges = [
            [1246406400000, 14.3, 27.7],
            [1246492800000, 14.5, 27.8],
            [1246579200000, 15.5, 29.6],
            [1246665600000, 16.7, 30.7]];
7
  • any console errors?, how do you know it doesn't push ? Commented Dec 14, 2016 at 6:23
  • Can you give an example array you want to process, what output your code is giving and the desired output for better understanding. Commented Dec 14, 2016 at 6:23
  • Possible duplicate of Three Dimensional Array in Javascript Commented Dec 14, 2016 at 6:23
  • Example array to push into 3d array (ranges) is like below '[22.5, 29.5, 19]. [21.5, 27.5, 15]' Commented Dec 14, 2016 at 6:38
  • This question is different from the existing one, where it was putting the value in desired index. But here i am pushing 3d value into an array. Commented Dec 14, 2016 at 6:41

1 Answer 1

0

Below is the way, how i got my results.

var ranges = new Array();
var averages = new Array();
var arrAverage;
var arrRanges;
arrAverage = [item.xAxisTime, item.yAxisValue];
arrRanges = [item.xAxisTime, item.upperBound, item.lowerBound];
averages.push(arrAverage);
ranges.push(arrRanges);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.