-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,

1
  • 1
    Welcome to Stack Overflow! Please take the tour (you get a badge!) and read through the help center, in particular How do I ask a good question? Your best bet here is to do your research, search 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 minimal reproducible example of your attempt and say specifically where you're stuck. People will be glad to help. Commented Mar 23, 2020 at 18:56

1 Answer 1

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);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.