Arrays in Vue
Displaying array contents in Vue is done the same way as in pure JavaScript. Let's see how it's done. Let's say in data we have a property arr that contains some array inside:
data() {
return {
arr: [1, 2, 3],
}
}
Let's print the elements of this array:
<template>
{{ arr[0] }}
{{ arr[1] }}
{{ arr[2] }}
</template>
Let data store the following array:
data() {
return {
arr: ['x', 'y', 'z'],
}
}
Print each element of this array in a separate paragraph.
Let data store the following array:
data() {
return {
arr: [1, 2, 3],
}
}
Display the sum of the elements of this array.