I'm new in programming and I'm going to be frontend developer. As part of the exercises i'm trying to do a simple web-app.
But to the point.
I got stuck while trying to filter/slice JSON object - only what I get from the console is: "slice/filter is not a function". I know that those functions are intended for arrays but I have no idea how to conver JSON object to JSON array. I looked a lot of staff in the Internet and tried to implement it but unsuccessfully...
There is the code:
<template>
<div class="class">
<section v-if="errored">
<p>We're sorry, we're not able to retrieve this information at the moment, please try back later</p>
</section>
<section v-else>
<div v-if="loading">Loading...</div>
<div class="row" v-else>
<div>
<div v-for="vehicle in filteredVehicles">
<img v-for="car in vehicle.cars" v-bind:src="car.url" v-bind:alt="car.name">
</div>
</div>
</div>
</section>
</div>
<script>
import axios from 'axios';
export default {
data() {
return {
vehicles: [],
loading: true,
errored: false
}
},
mounted() {
axios
.get('https://urlurlurl/vehicles.json')
.then(response => (this.vehicles= response.data))
.catch(error => {
console.log(error)
this.errored = true
})
.finally(() => this.loading = false)
},
computed: {
filteredVehicles: function () {
return this.vehicles.filter(function (v) {
return v.name === ('aaa' || 'bbb')
})
}
}
}
</script>
Sample of how the data is structured:
{
"1": {
"firstname": "",
"lastname": "",
"age": {
"1": {
"name": "",
"url": ""
},
"3": {
"name": "",
"url": ""
}
}
},
"2": {
"firstname": "",
"lastname": "",
"age": {
"6": {
"name": "",
"url": ""
},
"7": {
"name": "",
"url": ""
}
}
}
// etc.
}
Thank you in advance for your help.