Search code examples
phpjquerylogicbusiness-logic

php function array_keys equivalent in jquery


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


Solution

  • 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"]