【问题标题】:how to get the last digit from format like ip address javascript? [closed]如何从 ip 地址 javascript 等格式中获取最后一位数字? [关闭]
【发布时间】:2019-01-12 01:27:39
【问题描述】:

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

【问题讨论】:

标签: javascript typescript angular6


【解决方案1】:

好吧,如果那个 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)

【讨论】:

    【解决方案2】:

    使用

    let ip = '192.168.1.180';
    let last = ip.split('.')[3];
    console.log(last); // '180'
    

    【讨论】:

      猜你喜欢
      • 2010-09-29
      • 2013-01-18
      • 2023-03-10
      • 1970-01-01
      • 2013-02-06
      • 2012-06-16
      • 2011-08-14
      • 2019-02-13
      相关资源
      最近更新 更多