EN
JavaScript - how to get size of array inside object?
1 answers
0 points
How to get size of array inside object?
Let's say I have the following object
:
xxxxxxxxxx
1
var object = {
2
id: 1,
3
items: [
4
{ id: 1, value: 'a' },
5
{ id: 2, value: 'b' },
6
],
7
};
and I want to get number of elements inside items
array.
How can I do this?
1 answer
0 points
You can use dot property accessor to get the length
property value which is the number of elements inside an array.
Practical example:
xxxxxxxxxx
1
var object = {
2
id: 1,
3
items: [
4
{ id: 1, value: 'a' },
5
{ id: 2, value: 'b' },
6
],
7
};
8
9
var size = object.items.length;
10
11
console.log(size); // 2
References
0 commentsShow commentsAdd comment