Using freegeoip for a list of IPs

Please give me a simple tip where to dig!

I have multiple IP’s and need to display the location next to each of them.

I have a list of IPS in array via

var table = document.createElement('table');
table.innerHTML = forext;
var ips = [].slice.call(table.querySelectorAll('a[href*="?ip="]')).map(anchor => anchor.textContent).join("/n");

8.8.8.8
8.8.4.4 
...

I can get the location of each of them via input box

$('.send').on('click', function(){

  $.getJSON('https://ipapi.co/'+$('.ip').val()+'/json', function(data){
      $('.city').text(data.city);
      $('.country').text(data.country);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input class="ip" value="8.8.8.8">
<button class="send">Go</button>
<br><br>
<span class="city"></span>, 
<span class="country"></span>

BUT what I need is to print the IPs and the location next to it:

So, I have this:

8.8.8.8
8.8.8.8

BUT I need this

8.8.8.8 -Mountain View, US
8.8.8.8 -Mountain View, US
...

How can I proceed the whole array via http://freegeoip.net/json/? Thank you.

Update 1: Trying to make it using: ips[i]

var ipText='Lookup...';
var table = document.createElement('table');
table.innerHTML = forext;
var ips = [].slice.call(table.querySelectorAll('a[href*="?ip="]')).map(anchor => anchor.textContent).join("/n");

var ipLocations = [];

for(i=0;i<ips.length;i++){

 $.getJSON('https:/freegeoip.net/json/' + ips[i], function(data) {
    // could also use data.country_name, or any other property in the returned JSON
    var outputString = data.ips[i] + ' - ' + data.city + ', ' + data.country_code; 
    ipLocations.push(outputString);

  });

}

ipText = ipLocations.join('/n');
message.innerText = ipText;

First of all, you really want your IPs to be an array of strings, not a single string. As such, you should change your declaration for var ips = … and delete the .join(“/n”) from the end–that turns your convenient list of IP strings into a single string with the IPs separated by newline characters, which you don’t want.

Then, when you have an array of IP addresses of a form something like ips = [‘8.8.8.8’, ‘8.8.4.4’, … ];

…then you can get the output you described in the following way:

var ipLocations = [];
for ip of ips:
  $.getJSON('https:/freegeoip.net/json/' + ip, function(data) {
    // could also use data.country_name, or any other property in the returned JSON
    var outputString = data.ip + ' - ' + data.city + ', ' + data.country_code; 
    ipLocations.push(outputString);
  });

Now you have an array of strings with IP address + location, as you described. If you now want to turn THAT into a single string, you can do ipText = ipLocations.join(‘/n’); to get the output lines separated by newline characters.

If you’re going to be outputting this text into an HTML document though, you might want to join on <br> instead of /n, there are many contexts in which whitespace characters like /n will be ignored and you would end up with all your output on one line.