screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <title>Delete Property from Array of Objects</title> </head> <body> <p id="output"></p> <button onclick="deleteProperty('city')">Delete City Property</button> <script> let arrayOfObjects = [ { name: 'John', age: 30, city: 'New York' }, { name: 'Alice', age: 25, city: 'San Francisco' }, { name: 'Bob', age: 35, city: 'Seattle' } ]; let outputDiv = document.getElementById('output'); outputDiv.textContent = JSON.stringify(arrayOfObjects); function deleteProperty(propertyToDelete) { arrayOfObjects.forEach(obj => { delete obj[propertyToDelete]; }); let outputDiv = document.getElementById('output'); outputDiv.textContent = JSON.stringify(arrayOfObjects); } </script> <style> #output { background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } </style> </body> </html>