0

In Chrome console, this is what my array looks like when it has no data:

Object {Series1: Array[0]}

When it has data, it looks like this:

Object {Series1: Array[10]}

I tried this out but didn't have any luck:

function testfunction() {
    if (array[Series1] !== 'undefined' && array[Series1] !== null) {
        alert("There is data");
    } else {
        alert("No data here");
    }
};

$(document).ready(testfunction);
Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
John McCoy
  • 45
  • 1
  • 7
  • 1 - You dont have an array, you have an object that contains an array. 2 - possible duplicate of [How do I check if a (javascript) array value is empty or null](http://stackoverflow.com/questions/2672380/how-do-i-check-if-a-javascript-array-value-is-empty-or-null). – Craicerjack Jul 15 '15 at 15:40
  • Any idea how to test that the object has data based on the above example? – John McCoy Jul 15 '15 at 19:18

1 Answers1

3

Test the length of the array for an empty array:

if (array.Series1 && array.Series1.length) {
    //Populated
}

Also, unless Series1 in your sample was a variable, it has to be quoted for bracket notation.

tymeJV
  • 103,943
  • 14
  • 161
  • 157