[英]Find specific character from string and change its position to previous character using javascript, jquery
[英]Find a character from a string from its back
如何使用JavaScript从后面的网址中找到最后一个“ /”的位置。
像:如果我的URL是https://stackoverflow.com/questions/ask,那么我怎么能从后面找到最后一个“ /”的位置(在“询问”之前)
您可以使用String.prototype.lastIndexOf()进行此操作
var url = "http://stackoverflow.com/questions/ask";
var pos = url.lastIndexOf("/"); //returns the position of last occured /
lastIndexOf()
方法返回最后一次出现的指定值的调用String对象内的索引;如果未找到,则返回-1。
var aa='http://stackoverflow.com/questions/ask ';
Console.log(aa.lastIndexOf('/'));
采用
complete.lastIndexOf(part)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.