Welcome to
On Feet Nation
CWLS Melbourne Online
Florence Online
Jerry Online
Posted by priyankasharma on April 25, 2024 at 2:17am 0 Comments 0 Likes
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
© 2024 Created by PH the vintage. Powered by
You need to be a member of On Feet Nation to add comments!
Join On Feet Nation