Members

ES6 introduced many new methods built into the Array prototype. These methods allow you to interact with the data in your arrays in different ways, like transforming each item (map), sorting an array, or filtering an array. My favorite array methods that I use commonly in Vue apps are filter, map, forEach, and includes. Here’s an example using filter:

computed: {
// Without "filter" functional array method
oldFilteredItems() {
const filtered = []
for (const item in this.items) {
if(item.value > 10) {
filtered.push(item)
}
}
return filtered
},
// With "filter" functional array method
filteredItems() {
return this.items.filter((item) => item.value > 10)
}
}
This reduces the code we have to write (and read!) from seven lines to only one!

Read more: https://itmaster-soft.com/en/vue-js-development-services

Views: 7

Comment

You need to be a member of On Feet Nation to add comments!

Join On Feet Nation

© 2024   Created by PH the vintage.   Powered by

Badges  |  Report an Issue  |  Terms of Service