Right now, I am doing this in CoffeeScript:
keys = (key for key of data)
values = (v for k,v of data)
Where data is an an object (not an array). I am trying to create two arrays, where keys is an array of the property names and values is an array of the values.
This compiles to:
var keys, values;
keys = (function() {
var _results;
_results = [];
for (key in data) {
_results.push(key);
}
return _results;
})();
values = (function() {
var _results;
_results = [];
for (k in data) {
v = data[k];
_results.push(v);
}
return _results;
})();
I’d like to be able to combine these two loops into a single loop, and can’t figure out how (or if it’s possible) to do this using a list comprehension.
A different attempt I made was to create two arrays and push the items to them myself:
keys = []
values = []
keys.push k for k,v of data
This lets me push the key just fine, but I can’t figure out the syntax to push to values as well.
How can I create two arrays from a single list comprehension? Am I better off writing the loop myself?
I think the simplest would be to loop yourself:
which transpiles as