Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda