Wondering how to choose an object from an array in Vue.js:
When the page loads, the selectTitle() function is triggered. I simply want to select a specific object (for example, i=2) from my 'titleList' array. However, at the moment, I am only receiving an Observer as the output. I understand it has something to do with the scope or binding, but as a newcomer to Vue (and JS!), could someone please assist me?
Thank you!
var vm = new Vue({
el: '#titles',
data: {
titleList: [
{ title: 'Title1', details: 'details1', imgLocation:'', text: 'Lorem ipsum dolor sit amet.' },
{ title: 'Title2', details: 'details2', imgLocation:'', text: 'Lorem ipsum dolor sit amet.' },
{ title: 'Title3', details: 'details3', imgLocation:'', text: 'Lorem ipsum dolor sit amet.' },
{ title: 'Title4', details: 'details4', imgLocation:'', text: 'Lorem ipsum dolor sit amet.' },
{ title: 'Title5', details: 'details5', imgLocation:'', text: 'Lorem ipsum dolor sit amet.' }
],
},
mounted: function () {
this.setTimer();
this.selectTitle();
},
methods: {
selectTitle() {
let i = 2;
let currentTitle = this.titleList[i];
console.log(i, currentTitle);
return currentTitle;
},