![](/img/trans.png)
[英]How to get the number after particular string from array of strings using javascript?
[英]How to get particular part of string from an array of strings using javascript?
嗨,下面是字符串數組
const arr = [
"list/1/item/1/",
"some-domain/2/item/2/",
"item/3/",
"some-domain/4/item/5/subitem/1/",
]
使用
filter<\/code>以
item\/\\d+\/<\/code>開頭或結尾的路徑。
然后使用
map<\/code>從每個匹配路徑中提取項目編號。
這可能會有所幫助:
const filtered_arr = arr.map(str) => {
const match = str.match(/\/item\/(\d)/);
return(match[1]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.