Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
React Native Conditional Mapping Return

I have an array, splitByDay:

Array [
  Object {
    "Day": "Sunday",
    "data": "Upper",
  },
  Object {
    "Day": "Monday",
    "data": "Lower",
  },
]

and a function:

const getDay = (it) => {

          splitByDay.map((x, i) => {
            let day = x["Day"];
              if (day === it){

              return x["data"]
              } else { return "Rest" }
            
          })
      }

inside a FlatList, I pass in it which is the current day.

My goal is to return the corresponding piece of data if the day aligns. Here is the how its called:

 <Text style={[tailwind(`text-gray-300 font-[400px] text-[11px]`), {color: item === currentDay ? colors.purple : 'white'}]}>{getDay(item)}</Text>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is that you try to filter and map the data at once inside the map function. You should split that up, first filter the data and then map the data you want.

For example this code:

  const getDay = (it) => {
    return splitByDay.filter((x)=> x["Day"] === it).map((x) => x["Data"])[0]
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!