1

I got a array of days like this date = [22,25,30].

i can pass the date for each item like below which works fine.

But i wanted to pass the date dynamically to the this.highlightDays instead of doing it one by one.

How can i do it ? Please help

this.highlightDays = [
      {date: moment().date(22).valueOf()},
      {date: moment().date(25).valueOf()},
      {date: moment().date(30).valueOf()}
   ];
1
  • 1
    Do some research on mapping Commented Feb 8, 2018 at 20:27

1 Answer 1

4

Try Array.prototype.map

const dates = [22, 25, 30];

this.highlightDays = dates.map((date) => ({
    date: moment().date(date).valueOf(),
}));

console.log(this.highlightDays);
<script src="https://momentjs.com/downloads/moment.js"></script>

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

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.