0

I have two arrays:

var last13monthsofData = [0.45, 0.44, 0.46, 0.43, 0.4, 0.41, 0.46, 0.41, 0.4, 0.45, 0.46, 0.46, 0];
var last13monthsofDates = ["11/1/2013", "12/1/2013", "1/1/2014", "2/1/2014", "3/1/2014", "4/1/2014", "5/1/2014", "6/1/2014", "7/1/2014", "8/1/2014", "9/1/2014", "10/1/2014", "11/1/2014"];

I'd like to take these two arrays and make one new array of objects with corresponding data and dates:

the13monthDataDates=[
{"date":"11/1/2013","data":0.45},
{"date":"12/1/2013","data":0.44},
{"date":"1/1/2014","data":0.46},
{"date":"2/1/2014","data":0.43},
{"date":"3/1/2014","data":0.4},...];
2
  • Where did you get stuck? Commented Dec 22, 2014 at 23:39
  • you explained what you wanted, bit not what your problems were achieving it. Was the expectation to just have someone code this for you? Should really have a problem statement in your question Commented Dec 22, 2014 at 23:42

2 Answers 2

3

This should do:

var the13monthDataDates = $.map(last13monthsofData, function(v,k) {
    return {"date": last13monthsofDates[k], "data":v};
});
Sign up to request clarification or add additional context in comments.

Comments

3
var arr = [];
for (i = 0; i < last13monthsofData.length; i++) { 
    arr.push({ date: last13monthsofDates[i], data: last13monthsofData[i] });
}

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.