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

235
Views
obtenga una matriz, separe los valores separados por comas y luego vuelva a crear la matriz

Tengo la siguiente matriz:

 [ ["Polymeric", "Vehicle Graphics (Basic)"], ["Cast", "Vehicle Graphics (Part Wrap), Vehicle Graphics (Full Wrap)"], ["Polymeric", "Vehicle Graphics (Part Wrap)"] ]

Notará que las segundas líneas del segundo valor de la matriz tienen un valor separado por una coma. Quiero recrear la matriz así.

 [ ["Polymeric", "Vehicle Graphics (Basic)"], ["Cast", "Vehicle Graphics (Part Wrap)"], ["Cast", "Vehicle Graphics (Full Wrap)"], ["Polymeric", "Vehicle Graphics (Part Wrap)"] ]

Esto es lo que tengo hasta ahora:

 const media = [ ["Polymeric", "Vehicle Graphics (Basic)"], ["Cast", "Vehicle Graphics (Part Wrap), Vehicle Graphics (Full Wrap)"], ["Polymeric", "Vehicle Graphics (Part Wrap)"] ]; var filteredArray = media.filter(function(r) {return r[1]}) filteredArray.forEach(function(value) { var fgh = value.slice(1); var cddd = [value.shift()]; // takes first part var ttt = fgh.toString() var str_array = ttt.split(', '); const array3 = cddd.concat(fgh); console.log(str_array); });

Entiendo que necesito usar concat, dividir y finalmente empujarlo hacia atrás, pero intente lo que intente, no obtengo el resultado que necesito, así que necesito ayuda y ahora estoy perdido.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si puede asegurarse de que sus matrices anidadas siempre tendrán dos elementos, entonces es bastante simple:

 const source = [ ["Polymeric", "Vehicle Graphics (Basic)"], ["Cast", "Vehicle Graphics (Part Wrap), Vehicle Graphics (Full Wrap)"], ["Polymeric", "Vehicle Graphics (Part Wrap)"] ]; // Flat map instructs that // the nested arrays we're going to return // should be spread onto the root one source.flatMap(([key, value]) => { // [key, value] de-structs the array passed as a parameter // Here we're getting an array of all possible values; // if there's no ", " then we get a single element, // otherwise we get the whole collection of values const values = value.split(', ') // Now, for each of the individual values we create the key-value pairs return values.map(singleValue => [key, singleValue]) })

Rendimientos: ingrese la descripción de la imagen aquí

  • Matriz que desestructura JavaScript

  • Documentos para flatMap

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!