screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> function removeDuplicates(array, property) { return array.filter((obj, index, self) => index === self.findIndex((o) => o[property] === obj[property]) ); } function App() { const arrayOfObjects = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'John' }, { id: 4, name: 'Alex' }, { id: 5, name: 'Jane' }, ]; const uniqueArrayOfObjects = removeDuplicates(arrayOfObjects, 'name'); return ( <div className='container'> <h1>React Js Remove Duplicate Property from array of object</h1> <h3>Unique Value</h3> <ul> {uniqueArrayOfObjects.map((obj) => ( <li key={obj.id}>{obj.name}</li> ))} </ul> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 600px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } h1 { font-size: 28px; margin-bottom: 10px; color: #333; } h3 { font-size: 20px; margin-bottom: 10px; color: #666; } ul { list-style-type: none; padding: 0; margin: 0; } li { font-size: 16px; margin-bottom: 5px; color: #555; } li::before { content: '•'; display: inline-block; width: 10px; margin-left: -15px; color: #999; } </style> </body> </html>