-3

I have a JSON object which looks like this:

Object {
    @ID: "ID", 
    @Display: "Display", 
    @Order: "Order", 
    List: [
        {
            @ID: "ID", 
            @Name: "Name"
        }, 
        {
            @ID: "ID", 
            @Name: "Name"
        }]
    }

What I want to achieve is to return the property name if it is of type array. In the code example above, List should be returned. I have tried using $.isArray(indexOfProperty) but to no success. Any help please?

Rudolf Lamprecht
  • 1,050
  • 1
  • 14
  • 37

1 Answers1

2

You can use instanceof to check if a variable is an array. Try this:

for (var key in obj) {
    if (obj[key] instanceof Array) {
        alert(key + ' is an array!');   
    }
}

Example fiddle

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339