I spent all night working on this, and I know the answer is close; but I still have a lot of syntax work to do. Please do not downvote this - doing so only discourages newbies like me from asking questions. I need to create a function that accepts simple objects as an argument, and returns an array of arrays. Function should work on objects with any number of columns of properties with a simple string/number value. I'll show and explain my work in the codes I'll attach below:
//my first code:
var hi = {a: 1, b: 2, c: 3};
var props = new Array([],[],[]);
var lent = 0;
function newWave(hi){
for(var key in hi){
props[lent].push(key);
props[lent].push(hi[key]);
lent = lent + 1;
}
return props;
}
newWave(hi);
//function yields: [ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ]
//The return output is correct, but I need a universal code;
//looking at the number of columns in variable 'props', you can
//tell that this function only works on objects with 3 roperties.
//My second code:
function newWave(hi) {
var props = [];
var outcome = [];
for (var i = 0; i<1; i++){
for(var key in hi){
props.push(key, hi[key]);
outcome.push(props);
}
return outcome;
}
}
newWave(hi);
//This returns:
//[ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ],
// [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ],
// [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ]
//I feel like the answer is so close, but it's been 7 hours working on this,
//your help is greatly appreciated