Michał Warakomski
Michał Warakomski

Reputation: 15

React match by id and map to return in div

I am stuck with below, console.log shows correct but in web output there is no values shown. I would appreciate support

const ServicesDetails = [
  ["text1", "text2", "text3"],
  ["text5", "text6", "text7"],
  ["text8", "text9", "text10"]
];

const getServicesDetails = (prop) => {
  let length = ServicesDetails.length
  for (let i = 0; i <= length; i++) {
    if (parseInt(prop) === parseInt(i)) {
        ServicesDetails[i].map(
        (item, e) => {
          console.log(item, e)
          return <div key={e}>{item}</div>
        } 
      )
    }
  } 
}

Upvotes: 0

Views: 650

Answers (1)

Ozan Mudul
Ozan Mudul

Reputation: 1010

return your map https://codesandbox.io/s/condescending-glade-y78p00?file=/src/App.js

    let length = ServicesDetails.length;
    for (let i = 0; i <= length; i++) {
      if (parseInt(prop) === parseInt(i)) {
        return ServicesDetails[i].map((item, e) => {
          return <div key={e}>{item}</div>;
        });
      }
    }
  };

Upvotes: 1

Related Questions