-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiTester.js
More file actions
28 lines (26 loc) · 819 Bytes
/
apiTester.js
File metadata and controls
28 lines (26 loc) · 819 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
const axios = require("axios");
const url = "https://ror2api.morgantali.tech/items/passive/all";
axios.get(url).then((response) => {
const { data } = response;
for (item of data) {
let { stats } = item;
let collapsedStats = formatStats(stats);
console.log(collapsedStats);
}
});
function formatStats(data) {
let finalArray = [];
const objectKey = Object.keys(data);
for (let i = 0; i < objectKey.length; i++) {
const disassembled = data[objectKey[i]];
const objectKey2 = Object.keys(disassembled);
for (let j = 0; j < objectKey2.length; j++) {
if (typeof disassembled === "string") {
finalArray.push(`${objectKey[i]}: ${disassembled}`);
break;
}
finalArray.push(`${objectKey[i]}: ${disassembled[objectKey2[j]]}`);
}
}
return finalArray;
}