How to load Product by Sku or ID in Magento 2

magento

Load Catalog Product by SKU or ID

                $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

 

                $appState = $objectManager->get(‘\Magento\Framework\App\State’);

                $appState->setAreaCode(‘frontend’);

 

                $productRepository = $objectManager->get(‘\Magento\Catalog\Model\ProductRepository’);

 

                $id = 1; // YOUR PRODUCT ID;

                $sku = ’24-MB01′; // YOUR PRODUCT SKU

 

                // get product by product id

                $product = $productRepository->getById($id);

 

                // get product by product sku

                $product = $productRepository->get($sku);