php function array_keys equivalent in jquery

Manojkumar picture Manojkumar · Oct 9, 2012 · Viewed 8.2k times · Source

Possible Duplicate:
how to fetch array keys with jQuery?

php built-in function array_keys(), equivalent in jquery is there any built in function in jquery similar to that of php array_keys(),.

please suggest

Answer

Khior picture Khior · Oct 9, 2012

You will have to define your own function to get the same functionality. Try this:

function arrayKeys(input) {
    var output = new Array();
    var counter = 0;
    for (i in input) {
        output[counter++] = i;
    } 
    return output; 
}

arrayKeys({"one":1, "two":2, "three":3}); // returns ["one","two","three"]