screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Get Every nth Element of Array</h3> <p>Array: {{array}}</p> <p>Every nth Element:{{everyNthElements}}</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 2, // Set the desired value of n here }; }, computed: { everyNthElements() { return this.array.filter((_, index) => (index + 1) % this.nth === 0); }, } }); </script> <style scoped> #app { font-family: Arial, sans-serif; margin: 20px; } h3 { color: #333; } p { color: #777; } </style> </body> </html>