Even if you take regular backups as a matter of course, double-check that you have a working backup before wiping your device.
Follow Apple's guide to wiping your Mac.
Follow Apple's guide to wiping your iOS device.
Check if your device's manufacturer offers a guide on how to wipe your device securely.
If no advice is available, the safest option is to remove any storage devices (such as hard drives, or solid state disks) and physically destroy them.
If you use two-factor authentication which is linked to a specific device, you may need to disable this on each service, and then set it up again on your new device.
Check this before you wipe your device, as otherwise, you might lock yourself out of your online services.
Here.