How can I convert an array into a list of objects?
Turn
[
{
"currenttime":43481.46983805556,
"moped":"30 minutes",
"car":"1 hour"
}
]
into
{
"currenttime":43481.46983805556,
"moped":"30 minutes",
"car":"1 hour"
}
The data is retrieved from an external source and then the data edited using Vue.js
<script type="text/javascript">
const app = new Vue({
el: '#app',
data: {
items: []
},
created: function() {
fetch('https://example.com/delivery.json')
.then(resp => resp.json())
.then(items => {
this.items = items
})
}
});
</script>
I had originally tried to output using an expression of {{ items.car }} and {{ items.0.car }} with no success
arrayandlist of objects? What if you receive an array with two objects, do you want only the first one (meaningitems[0])?fetchcall, in two different ways: 1. You're not handling errors at all (you need to either add acatchhandler, or propagate the promise to something that will have acatchhandler), and 2. You're not checking.ok. Its' not just you, this second one is such a common mistake that I wrote it up in my anemic little blog.<div v-for="item in items">{{ item.car }}</div>instead of ditching the rest of the array.