How to get cart items in Magento 2?

For getting the cart items please use the below codehow-to-get-cart-items-in-magento-2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 

$itemsCollection = $cart->getQuote()->getItemsCollection();
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
$items = $cart->getQuote()->getAllItems();

foreach($items as $item) {
     echo 'Name: '.$item->getName().'<br />';
     echo 'Sku: '.$item->getSku().'<br />';
     echo 'Quantity: '.$item->getQty().'<br />';
     echo 'Price: '.$item->getPrice().'<br />';          
} 

Please leave your comment for asking any question or suggestion.

Need Help?how-to-get-cart-items-in-magento-2how-to-get-cart-items-in-magento-2