JavaScript - - By Sam Deering

jquery convert object to array

Some options for converting a jQuery object into an array. Also you can use a jQuery object much like an array. For example:

obj = $(‘p’); // Get all paragraphs into a jQuery object
for (i = 0; i < obj.length; i++) { // Do something with obj[i] } [/js] As you can see, jQuery objects have .length and []. But, .pop() and .reverse() are missing. And you may want to pass the array to a function that expects a native array. So do this: [js] obj = $('p'); // Get all paragraphs a = $.makeArray(obj); // One way to do it a = obj.toArray(); // The other way [/js] also try: [js] $.each(piv, function(name, value) { console.log(name, value); }); or this for (var key in piv) { // var obj = piv[key]; console.log(key, piv[key]); } [/js] Also see: