Is there a way to query an api or database with axios where an object element value is not the same as another object element value
Example: I am trying to get all titles ("title") where the "_ref" is not the same
{
"__v": 0,
"_ref": "6149290b197615d32c515dab",
"title": "First Title",
"details": "first"
},
{
"__v": 0,
"_ref": "6149290b197615d32c515dab",
"title": "First Title",
"details": "second"
},
{
"__v": 0,
"_ref": "2805jkdfg763",
"title": "Third Title",
"details": "third"
}
return await axios
.get('http://localhost/api', {
params: {
_ref: != _ref
},
})
.then(response => {
EventRegister.emit('MongoDb_Data', response.data);
return response.data;
})
.catch(err => {
console.log(err);
});
desired results would be:
First Title
Third Title
const data = [
{
"__v": 0,
"_ref": "6149290b197615d32c515dab",
"title": "First Title",
"details": "first"
},
{
"__v": 0,
"_ref": "6149290b197615d32c515dab",
"title": "First Title",
"details": "second"
},
{
"__v": 0,
"_ref": "2805jkdfg763",
"title": "Third Title",
"details": "third"
}
]
const refmap = data.reduce((acc, { _ref, title }) => {
acc[_ref] = {
title,
};
return acc;
}, {});
console.log('c', Object.values(refmap));
you will get the array of desired output.
console.log('c', Object.values(refmap).map( a => a.title)); // final output