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.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [employees] = useState([ { id: '1', name: 'David', role: 'Web Developer', department: 'Development', email: 'david@example.com', phone: '+1 123-456-7890', address: '123 Main Street, City, State, Zip', skills: ['HTML', 'CSS', 'JavaScript', 'React'], projects: [ { id: 'proj1', name: 'E-commerce Website', status: 'In Progress' }, { id: 'proj2', name: 'Portfolio Website', status: 'Completed' }, ], }, { id: '2', name: 'Andrew', role: 'Frontend Developer', department: 'Development', email: 'andrew@example.com', phone: '+1 987-654-3210', address: '456 Elm Avenue, City, State, Zip', skills: ['HTML', 'CSS', 'JavaScript', 'Vue.js'], projects: [ { id: 'proj3', name: 'Dashboard App', status: 'In Progress' }, { id: 'proj4', name: 'Blog Platform', status: 'Completed' }, ], }, { id: '3', name: 'Smith', role: 'Backend Developer', department: 'Development', email: 'smith@example.com', phone: '+1 555-123-4567', address: '789 Oak Road, City, State, Zip', skills: ['Node.js', 'Python', 'MongoDB', 'RESTful APIs'], projects: [ { id: 'proj5', name: 'User Management System', status: 'In Progress' }, { id: 'proj6', name: 'Task Tracking App', status: 'Completed' }, ], }, { id: '4', name: 'Emily', role: 'UX/UI Designer', department: 'Design', email: 'emily@example.com', phone: '+1 444-222-3333', address: '555 Pine Lane, City, State, Zip', skills: ['Adobe XD', 'Sketch', 'Illustrator', 'Prototyping'], projects: [ { id: 'proj7', name: 'Mobile App Redesign', status: 'In Progress' }, { id: 'proj8', name: 'Website Redesign', status: 'Completed' }, ], }, ]); const [result, setResult] = useState(''); const myFunction = () => { const foundEmployee = employees.find((employee) => employee.id === '4'); setResult(foundEmployee ? JSON.stringify(foundEmployee) : 'Employee not found'); }; return ( <div className='container'> <h2>React js array find function</h2> <p>Find Employees whose id is 4</p> <button onClick={myFunction} className="btn btn-primary"> Find Employee by id </button> <p></p> <p>{result}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { text-align: center; padding: 20px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); margin: 0 auto; width: 600px } h3 { color: #333; text-align: center; } </style> </body> </html>