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 Remove Empty Object From JSON</h3> <p>Original JSON array: {{ json }}</p> <p>Filtered JSON array: {{ filteredJson }}</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { json: [ { name: "John", age: 30 }, {}, { name: "Jane", age: 25 }, {}, { name: "Bob", age: 40 } ] }; }, computed: { filteredJson() { return this.json.filter(obj => { return Object.keys(obj).length !== 0; }); } } }); </script> <style scoped> #app { background-color: lightblue; padding: 20px; } h3 { color: darkblue; font-size: 24px; } p { color: black; font-size: 18px; } </style> </body> </html>