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

122
Views
how to get length of multi array in one object

I have object like this (nodename)

{
  BGF: [
    'bgf-simulator-pn',
    'bgf-simulator',
    'bgf-simulator-2',
    'bgf-1-error'
  ],
  Baseband: [ 'baseband_2', 'baseband_1' ],
  CCPC: [ 'ccpc-emulator' ],
  CCRC: [ 'ccrc-emulator' ],
  CEE: [ 'cee' ],
}

I want get length of array key

I used this way

    const nodename = await topologyBrowser.nodes();
    const arrayLength = Object.keys(nodename).length;
    console.log(arrayLength);

and console log return 5, but I want 9,

what did I wrong, what should I do guys

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can make use of Object#values() and use Array#flat() to flattern the multi-dimensional array.

Get the length like this: Object.values(nodename).flat().length!

See a working example-snippet below:

const nodename = {
  BGF: [
    'bgf-simulator-pn',
    'bgf-simulator',
    'bgf-simulator-2',
    'bgf-1-error'
  ],
  Baseband: ['baseband_2', 'baseband_1'],
  CCPC: ['ccpc-emulator'],
  CCRC: ['ccrc-emulator'],
  CEE: ['cee'],
};

const res = Object.values(nodename).flat().length;
console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

You can make use of Array#reduce() method:

const nodename = {
  BGF: [
    'bgf-simulator-pn',
    'bgf-simulator',
    'bgf-simulator-2',
    'bgf-1-error'
  ],
  Baseband: [ 'baseband_2', 'baseband_1' ],
  CCPC: [ 'ccpc-emulator' ],
  CCRC: [ 'ccrc-emulator' ],
  CEE: [ 'cee' ],
};

const result = Object.values(nodename).reduce((res, curr) => res + curr.length, 0);

console.log(result);

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!