第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何執(zhí)行類似于 forEach() 但使用下一行的操作?

如何執(zhí)行類似于 forEach() 但使用下一行的操作?

長風(fēng)秋雁 2023-07-14 15:05:52
如果我使用以下代碼:let original = "http://www.spur-g-shop.de/index.php?action=buy_now&BUYproducts_id=56&http://associations.beauvais.fr/en-un-clic/index.php?option=com_fabrik&view=list&listid=4&Itemid=520&asso_annuaireweb___id_soustheme_raw=40&sous_theme___ID_Theme=SPORTS&resetfilters=1http://laptopbank.net/product_detail.php?detail_id=B075FLBJV7https://www.music-scores.com/sheet-music/freeinstrument.php?instrument=Alto%20Saxhttp://www.traxjo.com/index.php?PageType=2&MenuID=1&Sub=1&Lang=1http://www.bizfocus.co.kr/admin/bbs/down.php?code=data&idx=8928&no=1http://www.vivitekthailand.com/en/Product_view.php?ProductId=115&CategoryId=7http://www.fsrm.ch/doc/c474.php?lang=e&id=474https://catalog.prm-catalog.com/index.php?lang=tw&ID=18&CatalogID=2839https://astacology.org/AboutCrayfish.asp?uid=Guest"當(dāng)然假設(shè)每個新行都是 \n我運行這段代碼:let dorks = original.split('/').pop().split('?')[0];console.log(dorks)它只返回:index.php(對于第一個網(wǎng)址)我怎樣才能讓它一起返回每一行?
查看完整描述

4 回答

?
MM們

TA貢獻(xiàn)1886條經(jīng)驗 獲得超2個贊

這是一個forEach可以為你做的:


    //note the use of a backtick here to allow your new line characters in string

    let original = `http://www.spur-g-shop.de/index.php?action=buy_now&BUYproducts_id=56&

    http://associations.beauvais.fr/en-un-clic/index.php?option=com_fabrik&view=list&listid=4&Itemid=520&asso_annuaireweb___id_soustheme_raw=40&sous_theme___ID_Theme=SPORTS&resetfilters=1

    http://laptopbank.net/product_detail.php?detail_id=B075FLBJV7

    https://www.music-scores.com/sheet-music/freeinstrument.php?instrument=Alto%20Sax

    http://www.traxjo.com/index.php?PageType=2&MenuID=1&Sub=1&Lang=1

    http://www.bizfocus.co.kr/admin/bbs/down.php?code=data&idx=8928&no=1

    http://www.vivitekthailand.com/en/Product_view.php?ProductId=115&CategoryId=7

    http://www.fsrm.ch/doc/c474.php?lang=e&id=474

    https://catalog.prm-catalog.com/index.php?lang=tw&ID=18&CatalogID=2839

    https://astacology.org/AboutCrayfish.asp?uid=Guest`


    //split on newline, and then for each URL, grab everything before the ? and trim extra spaces

    original.split("\n").forEach((url)=> console.log(url.split("?")[0].replace(/ /g,'')));


查看完整回答
反對 回復(fù) 2023-07-14
?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗 獲得超2個贊

有多種方法可以獲得您想要的東西。假設(shè)代碼更改最少,您的問題只是將邏輯應(yīng)用在多行上。


因此,最簡單的方法就是使用新行作為分隔符分割字符串,然后為每個字符串應(yīng)用您已經(jīng)編寫的代碼:


let s = `http://www.spur-g-shop.de/index.php?action=buy_now&BUYproducts_id=56&

http://associations.beauvais.fr/en-un-clic/index.php?option=com_fabrik&view=list&listid=4&Itemid=520&asso_annuaireweb___id_soustheme_raw=40&sous_theme___ID_Theme=SPORTS&resetfilters=1

http://laptopbank.net/product_detail.php?detail_id=B075FLBJV7

https://www.music-scores.com/sheet-music/freeinstrument.php?instrument=Alto%20Sax

http://www.traxjo.com/index.php?PageType=2&MenuID=1&Sub=1&Lang=1

http://www.bizfocus.co.kr/admin/bbs/down.php?code=data&idx=8928&no=1

http://www.vivitekthailand.com/en/Product_view.php?ProductId=115&CategoryId=7

http://www.fsrm.ch/doc/c474.php?lang=e&id=474

https://catalog.prm-catalog.com/index.php?lang=tw&ID=18&CatalogID=2839

https://astacology.org/AboutCrayfish.asp?uid=Guest`;


let dorks = s.split("\n").map(url => url.split('/').pop().split('?')[0]);


console.log(dorks)

請注意模板文字的用法,以便輕松獲取新行。

正如您所看到的,主要邏輯與您編寫的 () 完全相同,它只是使用mapurl.split("/").pop().split("?")[0]應(yīng)用于每一行。

map您可以使用正則表達(dá)式來解決這個問題,但我認(rèn)為這將有助于您了解如何在多行上應(yīng)用相同的邏輯(因此,如果邏輯發(fā)生變化,您可以輕松更改傳遞給的函數(shù)。


查看完整回答
反對 回復(fù) 2023-07-14
?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗 獲得超4個贊

我不完全確定您希望如何顯示匹配項,但以下是避免循環(huán)的方法:


let original = `http://www.spur-g-shop.de/index.php?action=buy_now&BUYproducts_id=56&

http://associations.beauvais.fr/en-un-clic/index.php?option=com_fabrik&view=list&listid=4&Itemid=520&asso_annuaireweb___id_soustheme_raw=40&sous_theme___ID_Theme=SPORTS&resetfilters=1

http://laptopbank.net/product_detail.php?detail_id=B075FLBJV7

https://www.music-scores.com/sheet-music/freeinstrument.php?instrument=Alto%20Sax

http://www.traxjo.com/index.php?PageType=2&MenuID=1&Sub=1&Lang=1

http://www.bizfocus.co.kr/admin/bbs/down.php?code=data&idx=8928&no=1

http://www.vivitekthailand.com/en/Product_view.php?ProductId=115&CategoryId=7

http://www.fsrm.ch/doc/c474.php?lang=e&id=474

https://catalog.prm-catalog.com/index.php?lang=tw&ID=18&CatalogID=2839

https://astacology.org/AboutCrayfish.asp?uid=Guest`;


let re = /[^.\/]+\.(?:php|asp)/g;


console.log(original.match(re));

console.log(original.match(re).join(' '));


查看完整回答
反對 回復(fù) 2023-07-14
?
大話西游666

TA貢獻(xiàn)1817條經(jīng)驗 獲得超14個贊

let original = `http://www.spur-g-shop.de/index.php?action=buy_now&BUYproducts_id=56&

http://associations.beauvais.fr/en-un-clic/index.php?option=com_fabrik&view=list&listid=4&Itemid=520&asso_annuaireweb___id_soustheme_raw=40&sous_theme___ID_Theme=SPORTS&resetfilters=1

http://laptopbank.net/product_detail.php?detail_id=B075FLBJV7

https://www.music-scores.com/sheet-music/freeinstrument.php? instrument=Alto%20Sax

http://www.traxjo.com/index.php?PageType=2&MenuID=1&Sub=1&Lang=1

http://www.bizfocus.co.kr/admin/bbs/down.php?code=data&idx=8928&no=1

http://www.vivitekthailand.com/en/Product_view.php?ProductId=115&CategoryId=7

http://www.fsrm.ch/doc/c474.php?lang=e&id=474

https://catalog.prm-catalog.com/index.php?lang=tw&ID=18&CatalogID=2839

https://astacology.org/AboutCrayfish.asp?uid=Guest`


original.split(/\s/).map(w => w.split('?')[0])

/* returns [

     "http://www.spur-g-shop.de/index.php", 

     "http://associations.beauvais.fr/en-un-clic/index.php",

     "http://laptopbank.net/product_detail.php",

     "https://www.music-scores.com/sheet-music/freeinstrument.php",

     "http://www.traxjo.com/index.php",

     "http://www.bizfocus.co.kr/admin/bbs/down.php",

     "http://www.vivitekthailand.com/en/Product_view.php",

     "http://www.fsrm.ch/doc/c474.php",

     "https://catalog.prm-catalog.com/index.php",

     "https://astacology.org/AboutCrayfish.asp"

   ] */

這/\s/是一個檢測各種空白的正則表達(dá)式。通過在所有空格的位置進(jìn)行拆分來從字符串創(chuàng)建數(shù)組后,您可以按照'?'您已經(jīng)執(zhí)行的操作再次拆分每個值。


確保字符串的方案與此完全相同。否則這個腳本可能會拋出錯誤。


查看完整回答
反對 回復(fù) 2023-07-14
  • 4 回答
  • 0 關(guān)注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號