Answer the question
In order to leave comments, you need to log in
Displaying the last element of an array in an array iterated over by v-for?
There is an array element:
{
/*бла бла*/
"messages": [{
/*бла бла*/
"value": "gwegweg",
/*бла бла*/
}, {
/*бла бла*/
"value": "ewfwef",
/*бла бла*/
}],
/*бла бла*/
}
elem.messages[elem.messages.length - 1].value
.value
reads normally without and outputs:{"value": "ewfwef"}
Answer the question
In order to leave comments, you need to log in
Kneepy , vue has great functionality for such tasks. It is called computed-properties.
You can add this to your component:
export default {
...
computed: {
lastMessage(){
return this.messages[messages.length-1]
}
}
...
}
lastMessage
<template>
...
{{ lastMessage.value }}
...
</template>
return this.messages[messages.length-1].value
<template>
...
{{ lastMessage }}
...
</template>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question