0

I have this function notify() with three parameters, user id(number), message, and link. On the website that I am working on, there are users that are invited to a party by a party host, and I wanna use this notify function to notify only those users that are invited. Every user has their own name and id (in numbers). But since the user id is a number, how do I use for loop (.each) to notify those users that are invited? For instance, there are 7 users (user 1-7), but only the users 1,3,5 are invited so I want to notify only 1,3, and 5.

P.S. This is what I have so far, I am so new to JQuery so please help!

if ($('#create-party-form').length) { //not sure if it's even right..
        $('#submit-invitation-btn').on('click', function() {
            $('').each(function() { //this is where I am stuck

            })
            notify( ,message, link); //first one should be id# of users that are invited..
        });
    }

Thank you in advance!

1
  • 1
    Trying to accomplish these things with no understanding of how the code works, is like trying to build a house without the understanding of construction code. You have to crawl before you can walk. You have to walk before you can run. Learn to crawl. Commented Apr 17, 2020 at 2:50

1 Answer 1

1

I'm not sure how you store the users, but assuming you have an array of user ids who are invited.

const invited = [1, 3, 5];
invited.forEach(id => notify(id, message, link);

This is also not using any jQuery, as you can see it is really simple.

Or perhaps you store the users like this?

{
  id: 3,
  name: 'Michael',
  invited: true
}

In that case, you can use filter:

users
  .filter(user => user.invited)
  .forEach(user => notify(user.id, message, link)
);
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.