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

166
Views
count the number of characters in 1 format

I have a text whose type is string and not array, as shown below:

'[123,456],[789],[10]'
  1. I want the count of number of arrays in this string(in this case it will be 3)
  2. I want the number of elements in each array.

I can't use split with commas because there are commas between the numbers in that "array".

And I need to determine the length of those 3 arrays, how do I do that?

Desired result:

array: 3
length: 2,1,1
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could add an array in the string so you end up with an actual json array.

Then you can parse the json and count them.

let value = '[' + '[123,456],[789],[10]' + ']';
let json = JSON.parse(value);
json.forEach((item, i) => {
  console.log('length: ' + item.length)
});
console.log(json.length + ' items')

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!