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 data = [ { name: "Apple", color: "red" }, { name: "Banana", color: "yellow" }, { name: "Kiwi", color: "green" }, { name: "Orange", color: "orange" }, { name: "Grapes", color: "purple" }, ]; const excludedFruits = ["Kiwi", "Grapes"]; // Names of fruits to skip const result = data.map(fruit => { if (excludedFruits.includes(fruit.name)) { // Skip the elements with names in the excludedFruits array return null; // You can use any value or component here } return ( <div key={fruit.name} className="fruit-item"> <p className="fruit-name">Name: {fruit.name}</p> <p className="fruit-color">Color: {fruit.color}</p> </div> ); }); return ( <div className='container'> <h3>React Js Skip Element of Array in .map() Function</h3> {result} <p> Skipped Element : {excludedFruits.join(',')}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; max-width: 600px; margin: 0 auto; } </style> </body> </html>