【发布时间】:2019-01-12 01:27:39
【问题描述】:
有谁知道我怎样才能得到最后一个数字192.168.1.180
示例: 192.168.1.180 从这个 IP 地址我想提取 180。
提前致谢
【问题讨论】:
-
到目前为止你尝试了什么?
标签: javascript typescript angular6
有谁知道我怎样才能得到最后一个数字192.168.1.180
示例: 192.168.1.180 从这个 IP 地址我想提取 180。
提前致谢
【问题讨论】:
标签: javascript typescript angular6
好吧,如果那个 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)
【讨论】:
使用:
let ip = '192.168.1.180';
let last = ip.split('.')[3];
console.log(last); // '180'
【讨论】: