I'm not sure if this is "elegant", but anyway:
function obj2arr(obj){
if(obj instanceof Array){
var ret=[];
for(var i=0;i<obj.length;i++){
if(typeof obj[i]=="object"){
ret.push(obj2arr(obj[i]));
}else{
ret.push(obj[i]);
}
}
return ret;
}else if(typeof obj=="object"){
var ret=[];
var keys=Object.getOwnPropertyNames(obj);
for(var i=0;i<keys.length;i++){
if(typeof obj[keys[i]]=="object"){
ret.push(obj2arr(obj[keys[i]]));
}else{
ret.push(obj[keys[i]]);
}
}
return ret;
}else{
return obj;
}
}
The following test:
console.log(obj2arr({
"data": [{
"timestamp": 1385118121279,
"value": 40
},{
"timestamp": 1385118301279,
"value": 7
}]
}));
Outputs:
[ [ [ 1385118121279, 40 ], [ 1385118301279, 7 ] ] ]
Online demo (I'm surprised to see that the JS engine in Ideone doesn't support Object.getOwnPropertyNames)
Although please be noted that this is a recursive solution, so big objects may causes stack overflow...
forstatement, or use.map()if you prefer.