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

150
Views
Cómo implementar el valor predeterminado de los pasos en la matriz

Tengo algunos pasos predeterminados por los que pasa mi pedido

 const defaultSteps = [ 'In preparation', 'Order taken from courier', 'Order is on its way', 'Order delivered to customer', 'Partner declined order' ];

Obtengo de la matriz de historial de back-end que contiene la fecha en que se cambia el estado y el nombre del estado

 history: [ { status_name: "In preparation", status_id: "62a74ac2fc767ef024f031cd", date_updated: 2022-06-14T20:29:51.784+00:00 }, { status_name: "Order taken from courier", status_id: "62a74ac2fc767ef024f031cd", date_updated: 2022-06-14T20:29:51.784+00:00 } ]

Quiero crear una nueva matriz que verifique si ese paso está en el historial, empuje ese elemento del historial con el campo de fecha a la matriz, de lo contrario empuje el elemento de los pasos predeterminados

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Si entiendo su pregunta, puede recorrer ambas matrices con Array.forEach() e insertar los elementos en la nueva matriz:

 const defaultSteps = [ 'In preparation', 'Order taken from courier', 'Order is on its way', 'Order delivered to customer', 'Partner declined order' ]; const result = [] const history = [ { status_name: "In preparation", status_id: "62a74ac2fc767ef024f031cd", date_updated: "2022-06-14T20:29:51.784+00:00" }, { status_name: "Order taken from courier", status_id: "62a74ac2fc767ef024f031cd", date_updated: "2022-06-14T20:29:51.784+00:00" } ] defaultSteps.forEach(str => { let hasMatch = false history.forEach(obj => { if(str === obj.status_name) { result.push(obj) hasMatch = true } }) if(!hasMatch) { result.push(str) } }) console.log(result)

about 4 years ago · Santiago Gelvez Report

0

Si entiendo bien la pregunta puedes hacer esto:

 const data = defaultSteps.map(item => history.find(i => i.status_name === item) || item)

los datos son su nueva matriz

about 4 years ago · Santiago Gelvez 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!