0

How covert or add array elements into object.

Now

arr = [
  ["1/1/2017",113],
  ["3/11/2017",58],
  ["3/12/2017",70],
  ["3/13/2017",76]
]

Should be

arr = [
  {date:"1/1/2017", count:113},
  {date:"3/11/2017", count:58},
  {date:"3/12/2017", count:70},
  {date:"3/13/2017", count:76}
]
1
  • 3
    1.3K rep and no effort posted? Commented Apr 10, 2017 at 11:17

1 Answer 1

3
arr.map(function(arr1) {
 return {
  date : arr1[0],
  count : arr1[1]
 }
})
Sign up to request clarification or add additional context in comments.

2 Comments

Or even arr.map(([date, count]) => ({ date, count }));
You are welcome

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.