I'm new to javascript and I was wondering how I would access the hash value and return the string so I can log it? Here's my code, I'm using axios.
Here's my code:
client.on("messageCreate", (message) => {
const args = message.content.slice(prefix.length).trim().split(' ')
const command = args.shift().toLowerCase();
if (command === 'search') {
let termargs = args.join(" ");
const options = {
method: 'GET',
url: 'https://breachdirectory.p.rapidapi.com/',
params: { func: 'auto', term: termargs},
headers: {
'x-rapidapi-host': 'breachdirectory.p.rapidapi.com',
'x-rapidapi-key': (keytouse, keys[keytouse]),
}
};
message.reply("searching...")
options.params.term = termargs
axios.request(options).then(function (response) {
console.log('Found:' , response.data["result"]);
}).catch(function (error) {
message.reply(JSON.stringify(error));
});
}
});
client.login(TOKEN);
Here's what it returns:
Found:
[
{ has_password: false, sources: [ 'Pluto.tv' ] },
{
has_password: true,
password: 'bleh',
hash: 'kMUX9351bsMjbgXH9rpKKf GIYJrJy4=',
sources: [ 'Aptoide.com' ]
},
{
has_password: true,
password: 'blah',
hash: 'lEiyXSecP9cIGJfyYhs8yteVEplUIRjAvaI7Jc76upI=',
sources: [ 'Collection 1' ]
},
{
has_password: true,
password: 'blahblahblah',
hash: 'djdrICyb/EfH6 R0g/26 d GIYJrJy6j',
sources: 'Unverified'
}
]
I tried doing response.data.results.hash but that didn't work. Any help would be appreciated. Thank you!
CodePudding user response:
the results is an array so :
response.data.results[i].hash
that "i" is a number like 0,1,...
CodePudding user response:
The response seems to be an array of objects, so maybe try looping throw the response and get the hash of each object. E.G:
axios.get('/user?ID=12345')
.then(function (response) {
response.data.forEach(item => {
console.log(item.hash);
});
})
If this doesn't work could you please share a console.log() of the response object?
The axios GET example was recover