How to get all the variants of Shopify products using js?

To get the varients of products we will use meta.To continue let’s see the below steps.

//code your js here

Now get the all variants in a variable.
var meta_variant = meta.product.variants;
Now, all the variants of product are in your meta_variant variable. Now you can get too many things on the basis of variant. Here we will get the price of current variant of product which is currently select. If we change the variant, then we get its price in alert.
last = meta_variant.length;
    // alert(last);
jQuery('form input[name=id]').change(function() {
   for (let i = 0; i < last; i++) {

    if(meta_variant[i].id == parseInt(jQuery('form input[name=id]').val()))
       current_varient_price =  meta_variant[i].price;
Now when you change variant you will get its price in alert form.
Note : few things like and input field may be varied according to Shopify themes. Kindly make appropriate change according to it.
Here is output when we change variant then alert will be popup with their price.