How can I add setTimeout() to promise of mapped async API fetch calls? [duplicate]

I’m trying to reduce the rate at which I make calls to this endpoint as to avoid 429 server error due to rate limit.

As a quick and inefficient way just to get it working for now, I’d like to do this using setTimeout(), though wherever I put it I get errors.

Here is the code I’m trying to slow down with a 1 second delay between calls:

    const getStaticProps = async () => {
        Promise.allSettled(
            urlsList.map((url) => fetch(url).then((resp) => resp.json()))
        ).then(console.log);
    };

how to do fetch 100 times at once – “not loop”? using pure JavaScript

I want to make a booking on a site that opens for booking only half an hour a week. During this time an enormous number of people rush to make booking. When the site gets highly crowded it is impossible for me to normally do my booking. thus, I must do a JS Fitch. However, neither doing fetch one time, nor doing fetch within a loop is enough. that’s already what I have made. otherwise, I should run fetches in parallel so that a request should be made let’s say a hundred times parallelly.

My question how to do for example 100 fetch, parallelly, each request.

  var registerUrl = "/API/booking.php";
  const params = {
    val1: document.querySelector('#val1').value.trim(),
    val2: document.querySelector('#val2').value.trim(),
    val3: document.querySelector('#val3').value.trim(),
    val4: document.querySelector('#val4').value.trim(),
    val5: document.querySelector('#val5').value.trim(),
    val6: document.querySelector('#val6').value.trim()
  };

const registerRequest = async (url) => {
    const response = await fetch( url ,
      {
          method: 'POST',
          body: new URLSearchParams(params)
      })
      .then((response) => {
              response.text().then((data) => {
                if(data.trim() == "success")
                {
                  console.log("donesuccessfully")
                }
              }
          });
      })
};


// here I need to do 100 request each loop
for (let i = 0; i < 1000; i++) {
    // each loop round I need to do registerRequest(registerUrl) * 100
    registerRequest(registerUrl); 
}
// the whole amount will be 1000 in loop and 100 parallels each loop

How to get JS ondragend event.pageY to not include toolbars (Firefox)

I’m trying to get the X and Y position of the mouse in a div for both JavaScript ondragstart and ondragend but produce different results.

The ondragstart function works as expected however onDragEnd is broken (says browser window rather than div).

What’s happening is that pageX/Y is counting the menu bars and bookmarks bar. The same thing happens if I use clientX/Y instead of pageX/Y.

I’m using Firefox desktop Linux Mint.

JavaScript

<script>
window.ondragstart = function(event){
    console.log(event.pageY); // works
}
window.ondragend = function(event){
    console.log(event.pageY); // different!
}
</script>

HTML

<div draggable="true" style="width: 100%; height: 560px; border: 1px solid black;">
</div>

How to let user copy CSS ::before content?

Text inserted via ::before and ::after cannot be selected and not copied.

How can I change this?

<style>
span::before{content:"including this text";}
</style>
<p>
If the text of this paragraph is selected and copied
then all of it should be copied
<span>instead of only this part</span>.
</p>

Using JavaScript instead of CSS is not acceptable. But the following JavaScript would be a acceptable:

  1. a function taking an element and returning the ::before text.
  2. a function taking an element and sitting its :: before text to display:none.

Create a Listed (Nested) Element in JSON

My question comes from this answer to a similar question. The comment below the answer sums up my question

how would the code look like if you would like to give depth to the tree? Like for name i would like to give name.firstname and name.lastname. Would I need to define name as var?

This is my current code

var jsonOutput =  new Object();;
jsonOutput.workflowID=1234;
jsonOutput.author="jonny"

I want to create a javascript object that looks like the below. I am stuck with creating the list of Tools. How would I do this?

{
  "workflowID": "1234",
  "author": "jonny",
  "tools": [
    {
      "toolid": "543",
      "type": "input",
    },
    {
      "toolid": "3423",
      "type": "input",
    },
    {
      "toolid": "1234",
      "type": "merge",
      "on": "Channel Name"
    }
  ]
}

How to copy paste a jQuery object but restrict what is pasted in different places?

We have a whiteboard editor (like Canva) on our page which contains a variety of items like an Image item, Text box item etc. When you copy one of them, a jQuery object is stringfied and is copied to the clipboard:

let myObject = {
    key: 'key',
    name: 'name'
};
let jsonString = JSON.stringify(myObject);
navigator.clipboard.writeText(jsonString);

The issue is that if you paste it in a text field, it pastes the stringified object hence exposing all the data. What I would like is that if we paste it anywhere but the editor, it pastes the name of this object only.

JavaScript/jQuery calling function assigned to private variable

I have a class defined in JavaScript which has a single public function which takes an options object to set some properties. One of the options is a callback function I need to call passing in a result (string value).

Inside the public function, there I set $.defered();, make a call to an internal function, and then retrieve the result in a .then(function(result){}); I can see the result value ok.

My issue is that I store the callback function in a private variable within the class #_callback_func; I can call this function from within the public function ok this.#_callback_func(‘test’);, however, it is dereferenced inside the then(function()), I get the old ‘cannot read property of undefined (reading #_callback_func)’ error.

My long term objective is to put the callback in a jQuery UI Dialog OK button which is set using the buttons: [ { text: ‘OK’, click: function(){ /* promise resolve + callback here */ }].

// basic code sample to give the idea.
 class MyTest {
  SomeCall = function(options) {
    // Set option, save return function
    this.#_callback_func = function(result) { alert('test: ' + result); }
    this.#_callback_func('test data'); // works

    this.#_a_promise = $.Deferred();
    this.#AnInternalFunc().then(function (result) {
      alert('result'); // shows appropriate result
      // Need to call equivalent of this.#callback_func(result) here, if it has been defined.
    });

    
  }
      #AnInternalFunc = function() {
      // do stuff and resolve the promise
      // will eventually display a jQuery UI dialog and handle OK/Cancel buttons.
      }
     #_callback_func;
     #_a_promise;
}

// Sample usage
var aTest = new MyTest().SomeCall({callback_func = function(result) {...});

I am aware there is a scope issue within the .then in terms of accessing the private variable – it is that I am trying to resolve.

Regards.

Any tips on writing a function to store and update the display number for my calculator?

I’m having trouble with calculating and displaying numbers with multiple digits on my calculator. I got chained operations working with single digits (not with the version below), but now if you try to input a number after the first operation it will add on. I know that the if statement if (display.textContent === displayValue) {display.textContent = '';} is not a viable solution (you can’t input the same number twice), but it’s the closest I got.

I simply need to figure out a way to clear the previous number before or as you input. I just can’t wrap my head around this one, any ideas would be greatly appreciated!

const display = document.querySelector('.display');
const equals = document.querySelector('#equals');
const clearBtn = document.querySelector('#clear');

function operate(operator, one, two) {
    display.textContent = '';
    if (operator === 'add') {
        return add(one, two);
    } else if (operator === 'multiply') {
        return multiply(one, two);
    } else if (operator === 'divide') {
        return divide(one, two);
    } else if (operator === 'subtract') {
        return subtract(one, two);
    }
}

function add(num1, num2) {
    return num1 + num2;
}

function subtract(num1, num2) {
    return num1 - num2;
}

function multiply(num1, num2) {
    return num1 * num2;
}

function divide(num1, num2) {
    return num1 / num2;
}

clearBtn.addEventListener('click', clear);

function clear() {
    display.textContent = '';
    displayValue = 0;
    lastDisplayValue = 0;
    operator = '';
    userInput.length = 0;
    lastOperation = 0;
}

let displayValue = 0;
let operator;
let lastOperation;

const userInput = [];

function inputCheck() {
    op1 = userInput[0];
    op2 = userInput[2];
    operator = userInput[1];

    lastOperation = operate(operator, op1, op2);
    display.textContent = lastOperation;
    userInput.splice(0, 3);
    userInput.unshift(lastOperation);
}

equals.addEventListener('click', function () {
    if (userInput.length === 4) {
        inputCheck();
    }
});

const digits = document.querySelectorAll('.digits');

digits.forEach(function (digit) {
    digit.addEventListener('click', function (e) {
        const element = e.target;
        if (element.classList.contains('digit')) {
            if (display.textContent === displayValue) {
                display.textContent = '';
            }
            // display.textContent = '';
            display.textContent += e.target.value;
        }
    });
});

const operators = document.querySelectorAll('.operator');

operators.forEach(function (operator) {
    operator.addEventListener('click', function (e) {
        const element = e.target;
        if (element.classList.contains('operator')) {
            displayValue = display.textContent;
            lastDisplayValue = displayValue;
            console.log(displayValue);
            console.log(e.target.value);
            userInput.push(parseInt(displayValue));
            userInput.push(e.target.value);

            if (userInput.length === 4) {
                inputCheck();
            }
        }
    });
});

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Calculator</title>
</head>

<body>

    <div class="calculator">
        <div class="display"></div>


        <div class="">
            <div class="topRow">
                <button id="clear">AC</button>
                <button value="divide" id="division" class="operator">/</button>
            </div>

            <div class="inputs">
                <div class="digits">
                    <button value="7" class="digit">7</button>
                    <button value="8" class="digit">8</button>
                    <button value="9" class="digit">9</button>

                    <button value="4" class="digit">4</button>
                    <button value="5" class="digit">5</button>
                    <button value="6" class="digit">6</button>

                    <button value="1" class="digit">1</button>
                    <button value="2" class="digit">2</button>
                    <button value="3" class="digit">3</button>
                    <button value="0" class="digit">0</button>
                </div>

                <div class="operators">

                    <button value="multiply" id="multiplication" class="operator">*</button>
                    <button value="subtract" id="subtraction" class="operator">-</button>
                    <button value="add" id="addition" class="operator">+</button>
                    <button value="equals" id="equals" class="operator">=</button>
                </div>
            </div>
        </div>

    </div>



    <script src="script.js"></script>
</body>

</html>
body {
    display: flex;
    flex-direction: column;
    /* justify-content: center; */
    align-items: center;
    background-color: black;
    height: 100vh;
}

.calculator {
    display: flex;
    flex-direction: column;
    width: 270px;
    background-color: rgb(37, 37, 37);
    padding: 15px;
    border-radius: 30px;
    margin-top: 50px;
}

.display {
    height: 80px;
    width: 270px;
    /* background-color: rgb(68, 68, 68); */
    font-family: Arial, Helvetica, sans-serif;
    color: white;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    font-size: 50px;
    border-radius: 10px;
    margin-bottom: 25px;
    margin-top: 10px;
}

.topRow {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

button {
    border-style: none;
    color: white;
    font-size: 30px;
    transition: 0.4s;
}

.digits {
    display: flex;
    flex-wrap: wrap;
    width: 200px;
    gap: 10px;
}

.digit {
    border-radius: 50%;
    width: 60px;
    height: 60px;
    background-color: rgb(68, 68, 68);
}

.digit:hover {
    background-color: rgb(154, 154, 154);
}

.operators {
    display: flex;
    flex-wrap: wrap;
    width: 60px;
    gap: 10px;
}

.operator {
    border-radius: 50%;
    width: 60px;
    height: 60px;
    background-color: orange;
    color: white;
}

.operator:hover {
    background-color: rgb(255, 255, 255);
    color: orange;
}

#clear {
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 20px;
    background-color: orange;
    color: white;
}

#clear:hover {
    background-color: red;
}

.inputs {
    display: flex;
    /* justify-content: space-between; */
    gap: 10px;
}

Show data from MySQL in a Leaflet marker in JavaScript

I want to display data from MySQL in a Leaflet marker.

 <div id="map"></div>
    <script>
        var map = L.map('map').setView([40.41889, -3.69194], 12);
        L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
        maxZoom: 18,
        id: 'mapbox/satellite-streets-v11',
        tileSize: 512,
        zoomOffset: -1,
        accessToken: 'pk.eyJ1IjoiYWxleHF1aWxpczEiLCJhIjoiY2wxbWI1MThrMGo1MDNjczltdXhwMG00YiJ9.VPlwJJoeRnSrbwBiv8MoHg'
        }).addTo(map);

        var runLayer = omnivore.kml('senda_132.kml')
            .on('ready', function() {
                map.fitBounds(runLayer.getBounds());
        })
        .addTo(map);
    </script>

In the var runLayer is loaded a .kml file with markers. In one of those markers I’d like to load the data from this table in MySQL:

    create table path
(
    id int,
    name varchar(500),
    category varchar(50),
    difficulty varchar(500),
    start varchar(500),
    final varchar(500),
    signals varchar(500),
    length varchar(500),
    max_level varchar(500),
    min_level varchar(500),
    primary key (id)
);

What’s the proper way to garbage collect?

I have some TypeScript code where a variable is of a certain type and can’t be assigned null nor undefined. If I want to reset its value, so that the previous one can be garbage collected, would it make sense to force it to undefined rather than an empty object, which is memory allocated for nothing?

type SomeType = { someProp?: number };

type MyType = { myProp: SomeType };

let variable: MyType = { myProp: { someProp: 5 } };

// What's the proper way to garbage collect?

// This
variable = { myProp: {} };

// Or this?
variable = {} as MyType;

// Or this?
variable = undefined as unknown as MyType;

Access to alien iframe in chrome extensions on the example of imacros and selenium ide

I’m writing a chrome extension and I’m having trouble accessing an iframe. I ended up googling this issue and all I got was “security policy” and why the iframe can’t be accessed.
In manifest.json “all_frames”: true does not help:

    "permissions": ["tabs","storage","<all_urls>","activeTab"],  
    "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["content.js", "raschet.js"],
      "run_at": "document_end",
      "all_frames": true
    }
    ],

I found a way to disable web security when turning on the browser: –disable-web-security(+ other settings).
If we do this and go to the site with recaptcha https://www.google.com/recaptcha/api2/demo,
after can use the code to click on the captcha:

document.querySelectorAll("iframe")[0].contentDocument.querySelectorAll("div[class='recaptcha-checkbox-border']")[0].click()

Yes it works, but disabling security is not my option.
There are programs for automating work in the browser iMacros and Selenium IDE. These are also extensions with javascript and here they were able to realize focus and click on the iframe.
Exampele iMacros:

FRAME F=1
TAG POS=1 TYPE=DIV ATTR=CLASS:recaptcha-checkbox-border&&ROLE:presentation&&TXT:

Exampele Selenium IDE:

command: select frame    target: index=0
command: click           target: css=.recaptcha-checkbox-border

Is it possible to repeat the same in my extension using JS or Jquery?

pass data from Javascipt to html props with a js file

I want the value in variable names to be displayed on div with id driverName. I have tried to set using innerhtml nothing has worked. Is there a way I can pass the variables to the content directly from the javascript file above. Once that one works am sure the rest I will do using the same solution.

 const arrayItem = item.split("#")
        .map((item, i) => `${item}`);
    var names = arrayItem[0];
    var location = arrayItem[1];
    var locationAddress = arrayItem[2];
    var regNo = arrayItem[3];
    var tripStatus = arrayItem[4];
    var startAddress = arrayItem[5];
    var endAddress = arrayItem[6];

    addMarker({
        coords: { lat: -1.294219, lng: 36.806824 },
        iconImage: taxi_available,
        content: `<p class="d-none">application|identifier</p><h6 class="d-flex align-items-center">
    <div class="card mb-0">
        <div class="card-body p-0 mb-2">
               <div class="d-flex">

               <div class="flex-shrink-0 align-self-center me-3">
                   <img src="assets/images/users/avatar-3.jpg" class="rounded-circle avatar-xs" alt="">
               </div>

               <div class="flex-grow-1 overflow-hidden pe-5">
                   <h5 class="text-truncate font-size-14 mb-1 text-capitalize">
                   <div id="driverName">{{$names}}</div>
                    <div class="rating-star">
                            <input type="hidden" class="rating" data-filled="mdi mdi-star text-warning" data-empty="mdi mdi-star-outline text-muted" data-readonly value="3.5" />
                        </div>
                   </h5>
                   <p class="text-truncate mb-0 text-uppercase">KAB 123P</p>
               </div>

               <div class="font-size-11 text-right">
                    <p class="text-muted mb-2"><i class="mdi mdi-circle text-primary align-middle me-1"></i> Available for Booking</p>
                    <p class="text-muted mb-0"><i class="mdi mdi-clock text-muted align-middle me-1"></i> Last seen at 12:23 AM</p>
               </div>
               </div>
        </div>

        <div class="card-body bg-light d-flex p-1>
            <p class="mb-0">
                <i class="mdi mdi-map-marker text-info align-middle me-1 font-18px"></i>
            </p>
        <div>
        <p class="text-muted mb-0">Current Location</p>
        <p class="mb-0">
        <span class="the-clicked-address"></span> Nairobi hospital, Ngong Road, Nairobi, Kenya
        </p>
       </div>
        </div>
    </div>`
    });

Below is my js function to add makers to the map

function addMarker(props) {
//add marker
var marker = new google.maps.Marker({
    position: props.coords,
    map: map,
    animation: google.maps.Animation.DROP,
    // icon:props.iconImage
});

if (!props.content) {
    gmarkers.push(marker);

}

if (props.iconImage) {
    //set icon image if its there
    marker.setIcon(props.iconImage);

}

// check if there is content
if (props.content) {
    //set icon image if its there

    var infowindow = new google.maps.InfoWindow({
        content: props.content
    });

    marker.addListener('mouseover', function(e) {

        infowindow.open(map, marker);

        var newCoords = e.latLng;
        newCoords = newCoords.toString();
        // alert(newCoords);

        var Latitude;
        var longitude;
        longitude = newCoords.substring(newCoords.lastIndexOf(",") + 1);
        Latitude = newCoords.substring(0, newCoords.indexOf(','));
        Latitude = Latitude.substring(Latitude.lastIndexOf("(") + 1);
        longitude = longitude.substring(0, longitude.indexOf(')'));

        reverseGeocoding(Latitude, longitude);
        // alert("mouse hovered");

    });

    marker.addListener('click', function(e) {
        toggleBounce(marker);

        var newCoords = e.latLng;
        newCoords = newCoords.toString();
        // alert(newCoords);

        var Latitude;
        var longitude;
        longitude = newCoords.substring(newCoords.lastIndexOf(",") + 1);
        Latitude = newCoords.substring(0, newCoords.indexOf(','));
        Latitude = Latitude.substring(Latitude.lastIndexOf("(") + 1);
        longitude = longitude.substring(0, longitude.indexOf(')'));

        reverseGeocoding(Latitude, longitude);


        // alert(iconImage);
        // alert( e.latLng);

        //position of the clicked marker . the longitude and latitude
        var pointPosition = e.latLng;

        //gettting the image

        //initializing image as empty
        var theImage = "assets/images/billboard-ads/no-add.jpg";

        //checking if the content has an image
        if (infowindow.content.includes("<img")) {
            //if it has image assign mage to

            theImage = infowindow.content.substring(infowindow.content.indexOf('src="') + 5);
            //the image url
            theImage = theImage.substring(0, theImage.indexOf('"'));


        }

        var theContent = infowindow.content.substr(18);
        var theContent = theContent.substring(0, theContent.indexOf('<'));

        //the group of markers eg car,incident,collection points etc
        var theGroup = theContent.substring(0, theContent.indexOf('|'));

        //the unique identifier of the clicked item eg number plate
        var uniqueIdentifier = theContent.substring(theContent.lastIndexOf("|") + 1);

        // alert(theGroup);

        //if else statements to bring out the correct side details depending on the groups category

        if (theImage != "") {
            $('#plate .plateImg').attr("src", theImage);
            $('.plateImg').removeClass('d-none');

        } else {
            $('.plateImg').addClass('d-none');
        }

        if (theGroup == "multi-plate") {

            $('#multi-plate .plateImg').removeClass('d-none');

            $('#multi-plate').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }

        if (theGroup == "plate") {

            $('#plate').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }

        if (theGroup == "plate-available") {

            $('#plate .plate-application-plate').removeClass('d-none').prev().addClass('d-none');

            $('#plate').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }

        if (theGroup == "application") {

            $('#application .plateImg').attr("src", theImage);

            $('#application').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }


        if (theGroup == "approved") {
            $('#approved .plateImg').attr("src", theImage);

            $('#approved').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }



        if (theGroup == "car") {
            //functions related to cars goes here
            $('#car-info').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");

        }

        if (theGroup == "incident") {
            //functions for incidents

            $('#incident-info').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");

        }

        if (theGroup == "collectionPoint") {
            //functions for collection points
            $('#collectionPoint-info').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }

        if (theGroup == "agent") {
            //function for agents
            $('#agents-info').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }

        if (theGroup == "offstreetParking") {
            //function for off street parking
            $('#offstreet-info').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");
        }

        if (theGroup == "street") {
            //function for on street parking
            $('#street-info').removeClass('left-100').siblings().addClass('left-100');
            $('.main-map-container .ma-backdrop').removeClass('d-none');
            $(".content, .header").append('<div class="ma-backdrop" data-ma-action="aside-close" data-ma-target=' + e + " />");

        }

        // this shows the more details
        // alert('clicked');

        var theCanvas = new bootstrap.Offcanvas(offcanvasExample)
        theCanvas.show()





    });

    // close content when mouse exits
    marker.addListener('mouseout', function() {
        infowindow.close(map, marker);

    });

}

}

Save item variable with Button Click

I want to create a web app which displays a number of customers from an API, and when I click on a customer, additional information for that customer will be shown.

So far I’ve fetched my API data as an array, created a list, and a button for each item in the array. Now when I push a customer button I want to call my API again but with the id as a parameter to access specific information about that customer.

However, to do so I need to save the “id” variable from the button that I pushed and I don’t understand how to implement that.

This is what my app looks like (in Svelte)

<script>
  import { onMount } from 'svelte'
    
  let customers = []

  onMount(() => {
    fetch('https://europe-west3-gcp-task-346814.cloudfunctions.net/customer-function-1/getCustomer')
      .then(response => response.json())
      .then(result => customers = result)
  })
    
  function handleClick() {
        
  }
    
</script>


{#each customers as customer (customer.id)}
<h2>
    <button on:click={() => handleClick()}>
    {customer.name}
  </button>
</h2>   

<p>
    id: {customer.id}
</p>
<hr>
{/each}

Note that I’m rather new to JS and HTML.