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

223
Views
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 answers
Answer question

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 Report

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 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!