2 回答

TA貢獻1798條經驗 獲得超3個贊
我無法確定,因為您沒有提供任何示例代碼,但fs
通常指的是Node.js中的“文件系統” ,因此其他主題的答案并不完整,但導入是由其用法暗示的:
var fs = require("fs")
fs.readFile(FILE_LOCATION, function (err, data) {
? if (err) throw err;
? if(data.indexOf('search string') >= 0){
? ?console.log(data)
? }
});
但正如其他一些評論者所說,這是針對 Nodejs 的,而不是在瀏覽器中。

TA貢獻1786條經驗 獲得超11個贊
如果您嘗試在瀏覽器中執行此操作,您可以獲取url 并使用include來檢查您要查找的字符串:
async function responseContains(url, string) {
? try {
? ? const content = await fetch(url).then(response => response.text());
? ? return content.includes(string);
? }
? catch (e) {
? ? console.log(e);
? ? throw e;
? }
}
const url = 'https://jsonplaceholder.typicode.com/todos/1';
/*
? the url above returns:
? {
? ? "userId": 1,
? ? "id": 1,
? ? "title": "delectus aut autem",
? ? "completed": false
? }
*/
responseContains(url, 'userId')
? .then(found => console.log(`Found 'userId'? ${found}`));
// Found? true
responseContains(url, 'wookies with bananas')
? .then(found => console.log(`Found 'wookies with bananas'? ${found}`));
// Found? false
- 2 回答
- 0 關注
- 109 瀏覽
添加回答
舉報