I want to restrict users to view list items which are not created by them.
Example: If I create a list item in a document library, Only I can view it, others should not see that information)
Is there any way to complete this task?
If you're talking about a list, not a document library, then you can do this:
Go to list settings -> advanced settings ->
Read access: Specify which items users are allowed to read select: Read items that were created by the user.
Same setting for "edit access". On document libraries this option is not available, I don't know why. There you could try using "Target Audiences" but I have no experience with that. I read that it only restricts the access on UI-Level. If users would try to access it via JSOM/CSOM this would still work.
Create a custom view for the list with a filter as
Created by: [Me].
You need to set item level permission dynamically based on user.
So you can create a workflow for that list in which condition is like current user is equal to Author and Action is Replace Item level permission.
Try, I hope it works.