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

92
Views
Quiero combinar los valores de los objetos en diferentes matrices ordenándolos por un lado

Quiero concatenar los valores de los objetos en diferentes matrices a un lado.
Traté de enviar el valor de los datos recibidos en json a console.log.

Quiero poner los valores de la Lista de ingredientes en la matriz de la Lista.

 console.log(detail); { List: [ { id: 120, content: "stack-overflow", functionalList: [ { id: 832, }, ], }, { id: 230, content: "heap-overflow", functionalList: [ { id: 24, }, ], }, ], ListValue: [ { IngredientList: [ { id: 1, value: 43 }, { id: 23, value: 23 }, ], }, ], }, ]);

Quiero poner los valores de ListValue -> IngredientList en el objeto de matriz de lista.
¿Cómo puedo hacerlo de esta manera? Lo he estado intentando todo el día, pero es difícil para mí.

 { List: [ { id: 120, content: "stack-overflow", value: 43 functionalList: [ { id: 832, functionalId: 37 }, ], }, { id: 230, content: "heap-overflow", value: 23 functionalList: [ { id: 24, functionalId: 12 }, ], }, ], ListValue: [ { IngredientList: [ { id: 1, value: 43 }, { id: 23, value: 23 }, ], }, ], }, ]);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

He resuelto esto. Míralo aquí: https://jsfiddle.net/bowtiekreative/o5rhy7c1/1/

Primero, su JSON necesita ser validado. Retire el ")" y el "," extra

Instrucciones

  1. Cree una matriz vacía llamada arr.
  2. Recorra la matriz ListValue.
  3. Para cada elemento de la matriz ListValue, recorra la matriz IngredientList.
  4. Para cada elemento de la matriz IngredientList, inserte la propiedad de valor en la matriz arr.
  5. Registre la matriz arr en la consola.

Ejemplo:

 var json = { "List":[ { "id":120, "content":"stack-overflow", "functionalList":[ { "id":832 } ] }, { "id":230, "content":"heap-overflow", "functionalList":[ { "id":24 } ] } ], "ListValue":[ { "IngredientList":[ { "id":1, "value":43 }, { "id":23, "value":23 } ] } ] }; var arr = []; for (var i = 0; i < json.ListValue.length; i++) { for (var j = 0; j < json.ListValue[i].IngredientList.length; j++) { arr.push(json.ListValue[i].IngredientList[j].value); } } console.log(arr)
about 4 years ago · Juan Pablo Isaza Report

0

Esto debería funcionar en un enfoque mutable, incluso si tiene varios objetos dentro de ListValue:

 data.List = [ ...data.List, ...data.ListValue.reduce((arr, el) => { arr.push(...el.IngredientList); return arr; }, []), ];
about 4 years ago · Juan Pablo Isaza Report

0

No está claro qué valor de IngredientList debe ir en qué elemento de List . Supongamos que siempre desea emparejar el primer valor con el primer elemento, el segundo con el segundo, y así sucesivamente...

 const obj = { List: [ { id: 120, content: "stack-overflow", functionalList: [ { id: 832, }, ], }, { id: 230, content: "heap-overflow", functionalList: [ { id: 24, }, ], }, ], ListValue: [ { IngredientList: [ { id: 1, value: 43, }, { id: 23, value: 23, }, ], }, ], }; const ingridientsValue = obj.ListValue[0].IngredientList.map(el => el.value); // [43, 23] for (const item of obj.List) item.value = ingridientsValue.shift(); console.log(obj.List);

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!