I created a Node Server and app.get('/links') route to grab entire image list. On FrondEnd I'm using standard HTML file with vanilla JavaScript and only $.get() JQuery function. Function perfectly loading data in console but for some reason I'm unable to use this data outside of $.get(). How can i read this data in standard JS Script embeded in HTML?
FrontEnd Script Embeded in HTML Code
$.get('/links', (data) => {
            loaddata(data);
        })
    let allImages= []
    let firstImg = ''
    let lastImg = ''
    let totalImgs = 0
    let currentImgIndex = 0    
    function loaddata(inpArr){
        totalImgs = inpArr.length
        firstImg = inpArr[0]
        firstImg = inpArr[totalImgs-1]
        allImages = inpArr
    }
NodeJs Route
var express = require('express')
var fs = require('fs');
var array = fs.readFileSync('links.txt').toString().replace(/\r\n/g,'\n').split("\n");
for(i in array) {
    console.log(array[i]);
}
app = express()
app.use(express.static(__dirname))
app.get('/links', (req, res) => {
    res.send(array)
})
app.listen(3000)
Links File
9th-Chem-2013-G1-011
9th-chem-ch-05-02
9th-chem-ch-05-03
9th-chem-ch-05-04
9th-chem-ch-05-05
