screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <h3>Vue Js Check if a key exists in an object</h3> <div id="app"> <label for="keyInput">Enter Key:</label> <input type="text" id="keyInput" v-model="checkKey"> <p v-if="keyExists(checkKey)">The key "{{ checkKey }}" exists in the object with value "{{ obj[checkKey] }}". </p> <p v-else>The key "{{ checkKey }}" does not exist in the object.</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { obj: { key1: "sarkarinaukriexams.com", key2: "fontawesomeicons.com", key3: 'tutorialsplane.com', key4: 'examly.org' }, checkKey: "key1" }; }, methods: { keyExists(checkKey) { return checkKey in this.obj; } } }) </script> </body> </html>