Tengo esta matriz múltiple y quiero convertirla en una matriz con códigos javascript y obtener datos de ella con flatMap :
[ { id: '46892319372', user_name: 'testerOne', identifier: '20202' } ] [ { id: '15243879678', user_name: 'testerTwo', identifier: '20201' } ] [ { id: '02857428679', user_name: 'testerThree', identifier: '20203' } ] [ { id: '65284759703', user_name: 'testerFour', identifier: '20204' } ]quiero convertir estas matrices múltiples en una sola matriz como esta con javascript: solo tengo una variable que contiene este ↓ o tal vez más de 4 o menos de 4 no sé, solo tengo una variable que contiene las matrices como esta en él y no puedo ponerlos en otra variable o separarlos con , o ... solo tengo esto ↓
[ { id: '46892319372', user_name: 'testerOne', identifier: '20202' }, { id: '15243879678', user_name: 'testerTwo', identifier: '20201' }, { id: '02857428679', user_name: 'testerThree', identifier: '20203' }, { id: '65284759703', user_name: 'testerFour', identifier: '20204' } ] Probé array.concat pero solo tengo una variable con esas matrices, así que probé list.concat(list) pero obtuve algo como esto como resultado:
[ { id: '46892319372', user_name: 'testerOne', identifier: '20202' }, { id: '46892319372', user_name: 'testerOne', identifier: '20202' } ] [ { id: '15243879678', user_name: 'testerTwo', identifier: '20201' }, { id: '15243879678', user_name: 'testerTwo', identifier: '20201' } ] [ { id: '02857428679', user_name: 'testerThree', identifier: '20203' }, { id: '02857428679', user_name: 'testerThree', identifier: '20203' } ] [ { id: '65284759703', user_name: 'testerFour', identifier: '20204' }, { id: '65284759703', user_name: 'testerFour', identifier: '20204' } ]Lo que tiene aquí no es una matriz múltiple (una matriz de matrices), sino múltiples matrices. No estoy seguro de cómo llegaste aquí, pero asumo que no los creaste, ya que la solución sería simplemente envolverlos en una matriz y separar cada matriz con una coma, entonces cualquier cosa que hagas para aplanarla funcionará.
Lo siento si esta es una respuesta demasiado rudimentaria por ahora.
¿Creó usted esto (puede editar fácilmente la estructura) o se los devolvieron?
No estoy seguro de si esto es lo que buscas, pero... esto solo funciona con arreglos que contienen objetos literales.
let arrayList = [ [{ id: '46892319372', user_name: 'testerOne', identifier: '20202' }], [{ id: '15243879678', user_name: 'testerTwo', identifier: '20201' }, { id: '15243879678', user_name: 'testerTwo', identifier: '20201' } ], [{ id: '02857428679', user_name: 'testerThree', identifier: '20203' }], [{ id: '65284759703', user_name: 'testerFour', identifier: '20204' }] ] function mergeArrays() { let arrayObject = [] for (let arrayLists of arguments) { for (let array of arrayLists) { if (array.constructor !== Array) continue; for (let object of array) { if (object.constructor !== Object) continue; arrayObject.push(object); } } } return arrayObject; } console.log(mergeArrays(arrayList))