Search code examples
javascriptjqueryarraysobject-literal

Convert object literal notation to array


I used a literal as a dictionary, but a third party binding tool only takes arrays.

This is one way, is there a better one?

var arr = [];
$.each(objectLiteral, function () { arr.push(this); });

Solution

  • I think there is nothing wrong with your solution.

    This is a shorter one:

    var arr = $.map(objectLiteral, function (value) { return value; });