本文翻译自:Converting a JS object to an array using jQuery
My application creates a JavaScript object, like the following: 我的应用程序创建了一个JavaScript对象,如下所示:
myObj= {1:[Array-Data], 2:[Array-Data]}
But I need this object as an array. 但是我需要将此对象作为数组。
array[1]:[Array-Data]
array[2]:[Array-Data]
So I tried to convert this object to an array by iterating with $.each
through the object and adding the element to an array: 所以我尝试通过$.each
遍历对象并将元素添加到数组中来将该对象转换为数组:
x=[]
$.each(myObj, function(i,n) {
x.push(n);});
Is there an better way to convert an object to an array or maybe a function? 有没有更好的方法将对象转换为数组或函数?
#1楼
参考: