I am learning d3 in javascript and am working on some basic data manipulation stuff. I have a simple JSON object of year / month / births data that looks like this:
var birthData = [
{
"year": 1967,
"month": "January",
"births": 31502
},
{
"year": 1967,
"month": "January",
"births": 26703
},
{
"year": 1967,
"month": "February",
"births": 28853
},
{
"year": 1967,
"month": "February",
"births": 26958
},
{
"year": 1967,
"month": "February",
"births": 28591
},
{
"year": 1967,
"month": "March",
"births": 29545
},
{
"year": 1967,
"month": "March",
"births": 30086
}]
and I would like to simply make an array of unique months that appear in this JSON object that looks like this:
["January", "February", "March"]
I would prefer to avoid using this approach
var months = [];
for(var i = 0; i <= birthData.length; i++) {
var month = birthData[i].month
if(months.indexOf(month) === -1) {
months.push(month)
}
}
Is there a more efficient way to do this?
EDIT: As a quick follow up question, are there any really good resources for learning data manipulation with javascript (particularly with d3 or other graphing libraries). Being very quick with data manip in javascript would make my life much easier!