screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue js check if item already exists in array</h3> <p v-if="itemExists">Item already exists in the array</p> <p v-else>Item does not exist in the array</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { myArray: ['apple', 'banana', 'orange'], myItem: 'banana' } }, computed: { itemExists() { return this.myArray.includes(this.myItem) } } }); </script> <style scoped> #app { font-family: Arial, sans-serif; background-color: #f2f2f2; padding: 20px; } h3 { font-size: 24px; color: #333; } p { font-size: 18px; color: red; margin-top: 10px; } </style> </body> </html>