-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindCommonText.js
More file actions
32 lines (27 loc) · 823 Bytes
/
findCommonText.js
File metadata and controls
32 lines (27 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require("fs");
// Read the JSON file
const jsonData = fs.readFileSync("locationOfJSONfile");
const data = JSON.parse(jsonData);
// Extract and process the image property
const resultArray = [];
data.forEach((item) => {
if (item.image) {
// Extract the desired part of the text
const imageUrl = item.image;
const slicedText = imageUrl.match(/:\/\/(.[^/]+)/)[1];
let obj = {
protocol: "https",
hostname: slicedText,
port: "",
pathname: "/***",
};
// Check if the text is not already in the result array
if (!resultArray.includes(slicedText)) {
resultArray.push(obj);
}
}
});
const resultFilePath = "result_array.txt";
fs.writeFileSync(resultFilePath, JSON.stringify(resultArray, null, 2));
// Output the result array
console.log(resultArray);