Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
Javascript Split String into Array of Arrays and not object

I have a string as input :

'PARTIALREFUND, 50, SUCCESS - PARTIALREFUND, 50, FAIL'

and i need to split the same into Array of Arrays , something like :

[[PARTIALREFUND, 50, SUCCESS],[PARTIALREFUND, 50, FAIL]]

I tired split on '-' , but that gives me an object with 2 keys , is there any other way to achieve this.

If required i can split

Solution Tired but did not worked:

const params = {postAuthActionId: 'PARTIALREFUND, 50, SUCCESS - PARTIALREFUND, 50, FAIL'};
const result = params.postAuthActionId.split('-').map((s) => s.split(','));
console.log(result);
console.log(typeof result);

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

split the string on - , and when you map over each element of the array return a new array, coercing the number from a string.

const params = {
  postAuthActionId: 'PARTIALREFUND, 50, SUCCESS - PARTIALREFUND, 50, FAIL'
};

const arr = params.postAuthActionId.split('- ');

const result = arr.map(el => {
  const [ id, number, status ] = el.split(', ');
  return [id, Number(number), status]
});

console.log(result);

about 4 years ago · Santiago Gelvez Denunciar

0

You can simply achieve it by using Array.map() along with spread (...) operator.

Demo :

const str = 'PARTIALREFUND, 50, SUCCESS - PARTIALREFUND, 50, FAIL';

const arr = str.split(' - ');

const res = arr.map(item => {
    return [...item.split(', ')]
});

console.log(res);

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda