1

Hi I have the following looking dataset:

[
    { date:"somedatehere", series1:"series1Value", series2:"series2Value" ..., seriesX:"seriesXValue"}, 
    { date:"anotherDateHere", series1:"anotherseries1Value", series2:"anotherseries2Value"...,seriesX:"anotherseriesXValue"},...
]

I'd like to loop through this in coffeescript and extract arrays such that I would have an array of dates (comprised of somedatehere, anotherDateHere, etc), series1 values, series2 values, seriesX values, etc.

Preferrably all of these arrays would go in order such that dates[0] === somedatehere and series1[0] === series1Value and series2[0] === series2Value and seriesX[1] === anotherseriesXValue etc.

Is there an easy way to go about doing this in coffeescript?

1 Answer 1

1
dates = (obj.date for obj in my_array)
series1 = (obj.series for obj in my_array)

in case you have a lot of series and don't want to manually enumerate them:

types = (k for k, v of my_array[0])
result = {}
result[type] =  (obj[type] for obj in my_array) for type in types

Will give you

my_array = [{date: 1, x: 2}, {date: 123, x: 2134}]

result = {
  date: [ 1, 123 ],
  x: [ 2, 2134 ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.