Condition inside map() function

PHOTO EMBED

Mon May 02 2022 17:13:08 GMT+0000 (Coordinated Universal Time)

Saved by @ruperto1 #condition #ifelse #operator

import React from "react";
import ReactDOM from "react-dom";

class App extends React.Component {
  render() {
    return [
      {
        name: "Sam",
        email: "somewhere@gmail.com",
        public: false
      },

      {
        name: "Ash",
        email: "something@gmail.com",
        public: true
      }
    ].map((anObjectMapped, index) => {
      return anObjectMapped.public ? (
        <p key={`${anObjectMapped.name}_{anObjectMapped.email}`}>
          {anObjectMapped.name} - {anObjectMapped.email}
        </p>
      ) : null;
    });
  }
}

ReactDOM.render(<App />, document.getElementById("container"));
content_copyCOPY

how you can make a condition inside a map function