0

I have a json as

var days = {mon: 1, tue:1, fri: 1}

What I'm trying to do it

var dayswithone =[];
['mon','tue','wed','thur','fri'].forEach(function(day){
    if(days.day){
      dayswithone.push(day);

    }
});

All i have to do is push days with 1 into array dayswithone. But this is giving me days.day as undefined.

2

2 Answers 2

1

You should try this

var dayswithone =[];
['mon','tue','wed','thur','fri'].forEach(function(day){
if(days[day]){
  dayswithone.push(day);

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

Comments

0

try days[day] instead of days.day;

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.