"namelist":{
"name":"xyz",
"version":"1.0.0"
}
How to find the length of the two values inside the namelist
?
"namelist":{
"name":"xyz",
"version":"1.0.0"
}
How to find the length of the two values inside the namelist
?
You can find size of object (i.e total number of attributes in object)like this:
namelist = { "name":"xyz", "version":"1.0.0" }
var size = Object.keys(namelist).length;
console.log(size);
Output: 2
For getting size of value of name
attribute ( e.g size of "xyz" in your case)
console.log(namelist.name.length)
Output: 3
For getting size of value of version
attribute( e.g size of "1.0.0" in your case)
console.log(namelist.version.length)
Output: 5
Get the keys as an array using Object.keys, and take the length of that array:
const obj = {
namespace: {
key1: 'whatever',
key2: 'whatever2',
}
}
const keys = Object.keys(obj.namespace) // ['key1', 'key2']
const keysLength = keys.length // 2