'Is there a way to extend code from one javascript file into another javascript file using imports

I am wanting to clean up my main javascript file so that it is easier to read. I have made classes and imported them into my main script but I was wondering if I could import blocks of code and use them as if they were essentially copied and pasted into my main script.

Here is an example of what I am kind of looking for:

const URL = "https://gateway.pinata.cloud/ipfs/QmPv2Z7odke1F1pTk7svwH291AFQepwoWEoZxCH7eRLpnD/"
var img = [];
var length = 10;
for(let i = 0; i < length; i++){
    img.push(new Image());
}

img[0].src = URL + "spriteStandRight.png";
img[1].src = URL + "spriteStandLeft.png";
img[2].src = URL + "spriteRunRight.png";
img[3].src = URL + "spriteRunLeft.png";
img[4].src = URL + "background.png";
img[5].src = URL + "hills.png";
img[6].src = URL + "platform.png";
img[7].src = URL + "platformSmallTall.png";
img[8].src = "https://gateway.pinata.cloud/ipfs/QmYpMv4Va39nQamQGcTPXyHCpT6kj1H8pdKzG7ZugznDBU";
img[9].src = "https://gateway.pinata.cloud/ipfs/QmTGZqE68EGbn4BE45bCmXwoXW7NsBsrQmBA43U4VfmS2r";

I am wanting to be able to have this code in a different file and then be able to import it into my main file and still be able to use the variables in the code. I know you can use "extends" for classes but I wasn't sure on how to go about it without the use of classes.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source