0

I am but new in JQuery, is there any mechanism to find out if one array element exists in another array. Like we do in linq in C#. I don't want to use for loop and if else

I am plotting a Highchart Graph in Jquery

I have 2 arrays

First 2D array contain data as X,Y cordinates like

                     2DArray =[2.0,6.31]
                              [3.0,6.09]
                              [4.0,7.44]

Another Array contain X Axis data like [1.0],[2.0],[3.0],[4.0]

2DArray first element is [2.0,6.31], but in the graph it starts from [1.0] point of X axis. I need if X axis point contains in 2DArray, only then Data passes in Graph.

This is what I have tried

    for (var i = 0; i < 2DArray.length; i++) {
        for (var x = 0; x < 1stArray.length; x++) {
            if (1stArray[x] == 2DArray[i][0]) {
                chart.addSeries({
                    name: "XX",
                    data: 2DArray
                }, false);
            }

        }
    }
} 

But it is not working ...

I find out there is contains method, but I am not sure how to actually use it. Any suggestion will be helpful

user3767164
  • 161
  • 1
  • 7
  • 19
  • isnt first value in 2D array actually x-axis data? why have another array? – Bojan Kovacevic Jul 07 '14 at 11:34
  • Try to plot the 2D array directly. highcharts takes it as (x,y) pairs.I think the verification and the second array is not needed – Strikers Jul 07 '14 at 11:43
  • exactly, highchart can use data: [[2.0,6.31],[3.0,6.09],[4.0,7.44]] format. – Bojan Kovacevic Jul 07 '14 at 11:48
  • I think that's duplicate of this: http://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items - it's exactly about merging two arrays without duplicates. – Paweł Fus Jul 07 '14 at 13:13

0 Answers0