Get the length of a JSON object in JS
Posted: 05 Dec 2020, 06:45
I have converted a database table into a JSON object.
This is in essence a two-dimensional array, with each record being the first dimension, which is an enumerated array, and the second dimension of fields, an associative array.
The number of the enumerated records, in the above example, 1-5, so that the number is this example would be '5'.
I've tried something like console.log(act_obj_array.length); , but the console displays undefined.
This is in essence a two-dimensional array, with each record being the first dimension, which is an enumerated array, and the second dimension of fields, an associative array.
Code: Select all
var act_obj_array ={
1: {act_id: "3", name: "Bruce Waelbrock Music Scholarship", category: "Life"},
2: {act_id: "4", name: "Christmas Childrens Gift Drive", category: "Community"},
3: {act_id: "5", name: "Church Drive", category: "Faith"},
4: {act_id: "6", name: "Church Kiosk", category: "Faith"},
5: {act_id: "7", name: "Consecration of the Holy Family", category: "Family"}
}
I've tried something like console.log(act_obj_array.length); , but the console displays undefined.