screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <h3>Vue js Convert Object into Array </h3> <div id="app"> <p>Object :{{myObj}}</p> <p>Array: {{items}}</p> <ul> <li v-for="(item, index) in items" :key="index"> {{ item.key }}: {{ item.value }} </li> </ul> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { myObj: { name: "John", age: 30, occupation: "Developer" }, items: [] } }, mounted() { this.items = Object.keys(this.myObj).map(key => ({ key, value: this.myObj[key] })); } }); </script> </body> </html>