Magento – Set select option default value as first one in Magento 2

htmlmagento2select

Today I am working with select controller, I have tried different ways to set the default value as the first one but can't. For this stuff, I tried below code.

Array

$colorProductId = array('2' => 'Black','3' => 'Blue');
<span class="select_span">Select Color: </span>
<select id="color_drop_down_options" data-role="color_drop_down_options" class="color_drop_down_options" onChange="check();">
   <?php foreach($colorProductId as $key => $value): ?>
        <option value="<?php /* @escapeNotVerified */ echo $value ?>"<?php if ($value): ?> selected="selected"<?php endif ?>>
            <?php /* @escapeNotVerified */ echo $key ?>
        </option>
   <?php endforeach; ?>
 </select>

Above code is selected last one see image.

enter image description here

please suggest me how to set first one as default selected.

Best Answer

Finally solved my self.

<script type="text/javascript">
    require(['jquery'],function($){
        $(document).ready(function() {
            $("#color_drop_down_options > [value='<?php echo $FirstIndex ?>']").attr("selected", "true");
        });
    });
</script>