I use the bellow code to get my requirement text:
var ipv4s = [
{ip: '1.1.1.1'},
{ip: '1.1.1.2'},
{ip: '1.1.1.3'},
{ip: '1.1.1.4'},
{ip: '1.1.1.5'},
{ip: '1.1.1.6'},
]
var ip_text = ''
for (let index in ipv4s) {
var item = ipv4s[index]
if(index === (ipv4s.length -1) ){
ip_text += item.ip
}else {
ip_text += (item.ip + ", ")
}
console.log(index, ipv4s.length - 1)
}
console.log(ip_text)
But I get the bellow console:
0 5
1 5
2 5
3 5
4 5
5 5
1.1.1.1, 1.1.1.2, 1.1.1.3, 1.1.1.4, 1.1.1.5, 1.1.1.6,
But in my think it will get the 1.1.1.1, 1.1.1.2, 1.1.1.3, 1.1.1.4, 1.1.1.5, 1.1.1.6
.
why there is a redundant ,
in there?