If we ask anything according to His will He hears us
“This is the confidence we have in approaching God: that if we ask anything according to his will, he hears us. And if we know that he hears us—whatever we ask—we know that we have what we asked of him.” (1 John 5:14-15)
We can come confidently to God in prayer when we are asking for things according to His will. How do you know if you are asking for things that are according to His will? You read His Word, find out what it says, and then you get in agreement with what it says! It's as simple as that.
If you are ever in doubt, talk to God about it (that's what prayer is). And, you can ask Him to give you wisdom about any situation. “If any of you lacks wisdom, let him ask God, who gives generously to all.” (James 1:5)