首页 > 解决方案 > 如何从 ip 地址 javascript 等格式中获取最后一位数字?

问题描述

有谁知道我怎样才能得到最后一位数字192.168.1.180
示例: 192.168.1.180 从这个 IP 地址我想提取 180。
提前谢谢

标签: javascripttypescriptangular6

解决方案


好吧,如果那个 ip 地址是一个字符串,你总是可以使用 split 函数。

let str = "192.168.1.180";
let x = str.split(".")[3]; 
// where str is the ip and x is the last part you want to extract

console.log(x)


推荐阅读