![](/img/trans.png)
[英]How do I split a value using the split function from javascript to split checking only the first and last occurence
[英]how do i split the url using split method by checking all the image extension
代碼:
var imgurl : String = http://sits/productimages/00670535922278.png?sw=350&sh=350 ; var imagesplit = imgurl.split('.(jpeg|png|jpg|gif)$/'); 我正在嘗試這段代碼,但它沒有分成數組。 我需要像
預期輸出:
圖片網址
[0]: http://sits/productimages/00670535922278.png?sw=350&sh=350 ;
誰能幫我看看這個
你總是可以嘗試這樣做;
var imgUrl = "http://sits/productimages/00670535922278.png?sw=350&sh=350;";
var splitterArray = ['.jpeg', '.png', '.jpg', '.gif'];
for (var i = 0; i < splitterArray.length; i++) {
var imgUrlArray = imgUrl.split(splitterArray[i]);
if (imgUrlArray.length > 1) {
//Do your thing here
}
}
您使用一組將被檢查的擴展名,我的字符串包含擴展名,您的 imgUrlArray 的長度大於 1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.