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

79
Views
Destructure object in ES2020

I have objects converted from JSON responses returned based on some conditions. The nodes of these 2 response objects would be same. but data would be different.How can I refactor and destructure below objects based on conditions?

if (searchType === "user") {
  const { user_search, details, education, work } = result?.data;
  search_data = user_search.results || [];
  total = user_search.total || 0;
  personalData = {
    details,
    education,
    work,
  };
}
if (searchType === "admin") {
  const { admin_search, details, education, work } = result?.data;
  search_data = admin_search.results || [];
  total = admin_search.total || 0;
  personalData = {
    details,
    education,
    work,
  };
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  const { user_search, admin_search, details, education, work } = result?.data;
  const result =  user_search || admin_search || [];
  search_data = result.results; 
  total = result.total || 0;
  personalData = {
    details,
    education,
    work,
  };
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!