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"> const { useState, useEffect } = React; function App() { const array = ['Laptop', 'Mobile', 'Mouse', 'Keyboard']; const mapped = array.map((value, index, array) => { if (array.length - 1 === index) { return `*****${value.toUpperCase()}******`; // Use toUpperCase() to change case } else { return value.toLowerCase(); // Use toLowerCase() to change case } }); console.log({ mapped }); return ( <div className='container'> <h3>React Js get last item in map function </h3> <ul> {mapped.map((item, index) => ( <li key={index}>{item}</li> ))} </ul> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Container */ .container { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); text-align: center; } h3 { font-size: 24px; color: #333; margin-bottom: 10px; } ul { list-style-type: none; padding: 0; } li { font-size: 18px; color: #666; margin-bottom: 8px; } /* Add hover effect to list items */ li:hover { background-color: #ddd; cursor: pointer; } </style> </body> </html>