-2

Platform: ReactJS

I am trying to combine the two arrays as a date:value object. Any thoughts?

a=["1/1/2020", "1/2/2020", "1/3/2020", "1/4/2020"]
b = [ 1, 2, 3, 4 ]

I am looking for the following result:

["1/1/2020":1, "1/2/2020":2, "1/3/2020":3, "1/4/2020":4]

Thank you,

singamnv
  • 91
  • 2
  • 10
  • 1
    Welcome to Stack Overflow! Please take the [tour] (you get a badge!) and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Your best bet here is to do your research, [search](/help/searching) for related topics on SO, and give it a go. ***If*** you get stuck and can't get unstuck after doing more research and searching, post a [mcve] of your attempt and say specifically where you're stuck. People will be glad to help. – T.J. Crowder Mar 23 '20 at 18:56

1 Answers1

0

You can try this approach.

const a=["1/1/2020", "1/2/2020", "1/3/2020", "1/4/2020"]
const b = [ 1, 2, 3, 4 ]

const c = {};
a.forEach((v, i) => {
 c[v] = b[i]
});

console.log(c);
Sajeeb Ahamed
  • 6,070
  • 2
  • 21
  • 30