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
>Solution :
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);