How to withdraw an under review manuscript from a journal when you decide you want to submit to another journal with a higher impact factor?
Technical aspects of withdrawal: Technically, you should be able to withdraw your manuscript from a journal any time prior to acceptance. This would usually be done either by using some kind of button in the submission management system, or by contacting the journal (e.g., editor, action editor, etc.).
Ethics and norms of withdrawal: However, there are reasons for withdrawing a manuscript that are appropriate and those that are inappropriate. After you submit your manuscript, the journal, the editors, and reviewers may begin expending effort and resources in processing your manuscript. It is considered poor form to waste their time, by withdrawing the manuscript for no good reason.
The appropriate time to consider impact factor is before you submit your manuscript to a journal. This is information that is available prior to submission. Thus, I think most academics would consider withdrawing a manuscript from a journal after submission based on impact factor to be very poor form.
In contrast, some acceptable reasons for withdrawing a manuscript during the peer-review process include the following:

You submitted to a predatory journal.
They are taking an excessive amount of time to process your submission.
Following a revise and resubmit, and you do not wish to make the revisions. That said, if the requested revisions are minor, and you withdraw at this point, this may not be received favourably by the editor.
You identify a fundamental flaw with your manuscript following submission. That said, minor problems can typically be addressed at the revision stage or by notifying the editor and asking them whether they would like you to correct the error now or at any potential revision stage.

Probably, if it is extremely early in the submission process, it would be more reasonable. E.g., you realise a few hours or perhaps a day after submission that you made a mistake.