How to get ordered items id by order id in Magento 2

If you want to get ordered items ID by order ID on Magento 2 website, follow these steps:How to get ordered items id by order id in Magento 2

Paste the following code in your PHP support file:
    $order_id = 205386;
    $order = $this->orderRepository->get($order_id);
    $item_data = [];
    $count = 0;
    foreach ($order->getAllVisibleItems() as $item) {
        //var_dump($item->getData());
        $item_data[$count]['item_id'] = $item->getItemId();
        $count++;
    }
    print_r($item_data);


Now your output will look like this:

(
    [0] => Array
        (
            [item_id] => 18
        )

)

How to get ordered items id by order id in Magento 2expoundsofttechsolution
d