I want to split a text file line by line, and then on encountering a character in the line (':'), to store it in an array. I need that array to plot points on a map. I can do the plotting fine when I do it with a static array.
var map = new google.maps.Map(document.getElementById('map'), googleMap);
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(infowindow, "closeclick", function() {
map.fitBounds(latlngbound);
map.panToBounds(latlngbound)
})
var ipArray = ["70.177.167.189", "123.135.107.115", "123.135.107.115", "123.135.107.115", "123.135.107.115", "122.182.6.19", "24.19.187.145", "24.19.187.145", "24.19.187.145", "93.42.228.21", "82.102.2.210"];
ipArray.forEach((ip) => {
addIPMarker(ip);
})
} catch(e){
//handle error
}
However, I'm not able to do it when I follow this methodology -
var map = new google.maps.Map(document.getElementById('map'), googleMap);
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(infowindow, "closeclick", function() {
map.fitBounds(latlngbound);
map.panToBounds(latlngbound)
})
var data_ip = [];
var textByLine = [];
readTextFile("./2017-12-12.txt", data_ip);
var fs = require("fs");
fs.readFile("./2017-12-12.txt", function(text){
textByLine = (text.split("\n")).split(":")[0];
});
textByLine.forEach((ip) => {
addIPMarker(ip);
})
} catch(e){
//handle error
}
Can anyone tell me where I'm going wrong, and how I can correct my code. I'm not very familiar with JavaScript. So, I'm not really sure what exactly I'm doing here. Any help appreciated! Thanks!