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

119
Views
Optimize the display value in React Js

Please let me know how I can optimize more below code in one line:

 {addressToDisplay?.addressLineOne}
      {addressToDisplay?.addressLineTwo}
      {addressToDisplay?.city}
      {addressToDisplay?.state}
      {addressToDisplay?.zip}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

if your object is already well organized you can do this

return <>{[...Object.values(addressToDisplay || {})].join` `}</>;

Or else you have this kind of solution

const {addressLineOne, addressLineTwo, city, state, zip} = addressToDisplay || {};
    
return <>{[addressLineOne, addressLineTwo, city, state, zip].join` `}</>
about 4 years ago · Juan Pablo Isaza Report

0

You can try this out:

Object.keys(addressToDisplay).map(function(key) {
   return <>{ addressToDisplay[key] }</>
})

And to display both key, value you can add:

Object.entries(addressToDisplay).map(([key, val]) => 
                    <h2 key={key}>{key}: {val}</h2>
                )

If you need specific values then you can store the keys which you need in one array

addressField = ['city', 'state', 'lineone', 'linetwo']

and then get them by

{addressToDisplay && addressField.map(key => <>{addressToDisplay[key]}</>)}
about 4 years ago · Juan Pablo Isaza Report

0

{addressToDisplay && addressField.map((key) => <>{addressToDisplay[key]}</>)}

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!