How can I pass a variable to javascript from a preprocess function? How do I pass $variables['is_front'] from template_preprocess_page() to a jquery script in Drupal8?
send it:

function mytheme_preprocess_page(&amp;$variables) {
   $variables['#attached'] = [
        'drupalSettings' =&gt; [
          'myLibrary' =&gt; [
            'is_front' =&gt; $variables['is_front'],
          ],
        ],
    ];
}


access it in jquery:

  Drupal.behaviors.myBehaviour = {
    attach: function (context, settings) {

      console.log(settings.myLibrary.is_front);

    }
  };