John tells us his purpose in writing his first epistle.

I write these things to you who believe in the name of the Son of God, that you may know that you have eternal life. (1 John 5:13)

The whole purpose was that you may know that you have eternal life. Note that it was written to specific people. It's not for everyone. It is written "to you who believe in the name of the Son of God." But the intent is clear. You can know that you have eternal life.

It is interesting, then, to read through John's repeated use of the phrase, "By this we know." Since "knowing" was his reason for writing it, "by this we know" is a helpful concept. In fact, John uses this kind of wording eight times in his little epistle. Beyond that, there's a whole lot of "knowing" going on in 1John.

My little children, I am writing these things to you so that you may not sin. But if anyone does sin, we have an advocate with the Father, Jesus Christ the righteous. He is the propitiation for our sins, and not for ours only but also for the sins of the whole world. And by this we know that we have come to know Him, if we keep His commandments. Whoever says "I know Him" but does not keep His commandments is a liar, and the truth is not in him, but whoever keeps His word, in him truly the love of God is perfected. By this we may know that we are in Him: whoever says he abides in Him ought to walk in the same way in which he walked. (1 John 2:1-6)

I had to give you that whole text because it contains several essential elements in the question of assurance. First, note that the primary question is relationship. The primary question is "Have I come to know Him?" It is the failure of those in Matthew 7:21-23 where Jesus declares, "I never knew you." You are saved if you have a genuine relationship with Christ -- with the Christ of the Bible. Second, the test is obedience. We know we have a relationship with Him if we keep His commandments. This isn't news. Jesus said the same thing (John 14:15,23-24). The test of relationship is in what we do. Makes sense. "I love God but have no interest in pleasing Him" makes no sense. At this point the third element in this text becomes vital. "Does this mean that if I don't obey perfectly I can't be assured of salvation?" Not at all. John said "If anyone does sin, we have an advocate." That is, we all sin (1 John 1:8). The obedience in view here, then, is not "sinless perfection," but a direction. If you aim toward less sin and more obedience, you can be confident that you have a relationship with Christ. If you figure you're doing fine where you are or just don't really concern yourself over it, you might need to ask the question. If "What does the Lord require of me?" isn't one of your primary questions, you might need to see if you're even in the faith.

We know that we have passed out of death into life, because we love the brothers. Whoever does not love abides in death. (1 John 3:14)

John offers certain knowledge here. We can know that we have been saved -- that we have already passed from death to life. What is the test? "We love the brothers." Simple. Do you consider fellow believers of some importance? Do you seek their company, enjoy their fellowship, care about their well-being? Do you actively love believers (1 John 3:17-18)? It was Jesus's idea that this would demonstrate to the world that you are His disciple (John 13:35). For you, not so much? You might need to examine your relationship with Christ.

These two ideas -- obedience and love of the brethren -- are repeated in John's epistle.
By this we know love, that He laid down His life for us, and we ought to lay down our lives for the brothers. But if anyone has the world's goods and sees his brother in need, yet closes his heart against him, how does God's love abide in him? Little children, let us not love in word or talk but in deed and in truth. By this we shall know that we are of the truth and reassure our heart before Him; for whenever our heart condemns us, God is greater than our heart, and He knows everything. Beloved, if our heart does not condemn us, we have confidence before God; and whatever we ask we receive from Him, because we keep His commandments and do what pleases Him. And this is His commandment, that we believe in the name of His Son Jesus Christ and love one another, just as He has commanded us. Whoever keeps His commandments abides in God, and God in Him. And by this we know that He abides in us, by the Spirit whom He has given us. (1 John 3:16-24)
This one sounds a lot like Paul's idea in Romans. "The Spirit Himself testifies with our spirit that we are children of God" (Romans 8:16). But remember, that isn't just a warm feeling, a secret conversation between your heart and the Spirit. It is predicated on a changed person who is putting to death the deeds of the flesh, who is walking by the Spirit, who is no longer that same person that pursued sin. If you have had a change of heart, a new direction, a new motivation to pursue God rather than self, that is clear evidence. No one can be born of God and powered by the Spirit without a change. If you think you're a Christian and don't really change much ...
You are from God, little children, and have overcome them; because greater is He who is in you than he who is in the world. They are from the world; therefore they speak as from the world, and the world listens to them. We are from God. Whoever knows God listens to us; whoever is not from God does not listen to us. By this we know the Spirit of truth and the spirit of error. (1 John 4:4-6)
How do we know the Spirit of truth and the spirit of error? The spirit of error is "from the world." If "the world listens to them," it is error. We can know this. Who are you listening to? What is your source? If your source is the world's wisdom and you are evaluating God and His Word by the world's standards, you might have something to be concerned about.

How about this one?
By this we know that we love the children of God, when we love God and observe His commandments. For this is the love of God, that we keep His commandments; and His commandments are not burdensome. (1 John 5:2-3)
Now, perhaps you already see the connection. Remember that we already learned that one way we know that we have passed out of death into life is if we love God's people. So how do we know if we love God's people? "When we love God and observe His commandments." Nice packaging, isn't it? Loving God and obeying Him is evidence that we are saved. Loving God and obeying Him is how we love the children of God. It's all tied up neatly. That is, if you are loving God, obeying Him, and loving His people. If not, there might be a need for reconsidering your spiritual condition.

Now, remember, this isn't a "pass-fail" kind of thing. The command, for instance, is to love God with all our hearts, mind, souls, and strength. Not one of us does that. So the point is not absolute obedience or else. The point is direction. You see, if it is true that the mind set on the flesh cannot please God (Romans 8.7-8" data-version="nasb95" data-purpose="bible-reference" target="_blank" style="text-decoration-line: none; color: rgb(70,149, 156); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px;">Romans 8:7-8), then anyone whose aim is to please God by loving Him and obeying Him is demonstrating a changed heart. If these things are yours and increasing, you can have confidence before God. Not perfection; direction. None of this is unattainable (Philippians 2:13). Either you're headed one direction -- loving God, His commands, and His people -- or you're not. Away from self or toward self. Pursuing God's Word and God's will over against (rather than in accordance with) the world's views and values. Ask yourself. You're the one who has to answer.