I have a nested object with nested array objects. I need to extract each object separately. This is a sample of the object:
records = [{"keys":["voters","groups"],"length":2,"_fields":[{"identity":{"low":14,"high":0},"labels":["Voter"],"properties":{"name_key":"AINSWORTHLLOYDCECIL","occupation":"CARPENTER","gender":"MR","street":"12 ST JAMES ROAD","name":"LLOYD AINSWORTH","last_name":"AINSWORTH","middle_name":"CECIL","postal_code":"KGN 02","first_name":"LLOYD"}},{"identity":{"low":23666,"high":0},"labels":["Group"],"properties":{"name":"IMGroup","description":"Master group for individual members","since":{"low":-661343024,"high":374},"status":"active"}}],"_fieldLookup":{"voters":0,"groups":1}},{"keys":["voters","groups"],"length":2,"_fields":[{"identity":{"low":15,"high":0},"labels":["Voter"],"properties":{"name_key":"ALEXANDERDWAYNEBARRINGTON","occupation":"AIR CON TECH","gender":"MR","street":"3 1/2 JOHNSON TERRACE","name":"DWAYNE ALEXANDER","last_name":"ALEXANDER","middle_name":"BARRINGTON","postal_code":"KGN 02","first_name":"DWAYNE"}},{"identity":{"low":23666,"high":0},"labels":["Group"],"properties":{"name":"IMGroup","description":"Master group for individual members","since":{"low":-661343024,"high":374},"status":"active"}}],"_fieldLookup":{"voters":0,"groups":1}},{"keys":["voters","groups"],"length":2,"_fields":[{"identity":{"low":16,"high":0},"labels":["Voter"],"properties":{"name_key":"ALLENANNETTEUNA","occupation":"COSMETOLOGIST","gender":"MISS","street":"28 CARNARVAN STREET","name":"ANNETTE ALLEN","last_name":"ALLEN","middle_name":"UNA","postal_code":"KGN 02","first_name":"ANNETTE"}}........]
I am accustomed to using
records.map(obj => obj.get(0).properties ? obj.get(0).properties : obj.get(0));
or
records[0].get('voters').properties
for some reason I am getting
obj.get is not a function
I am not sure what I a missing here...would appreciate some help.
Here is the reproduction:
records = [{
"keys": ["voters", "groups"],
"length": 2,
"_fields": [{
"identity": {
"low": 14,
"high": 0
},
"labels": ["Voter"],
"properties": {
"name_key": "AINSWORTHLLOYDCECIL",
"occupation": "CARPENTER",
"gender": "MR",
"street": "12 ST JAMES ROAD",
"name": "LLOYD AINSWORTH",
"last_name": "AINSWORTH",
"middle_name": "CECIL",
"postal_code": "KGN 02",
"first_name": "LLOYD"
}
}, {
"identity": {
"low": 23666,
"high": 0
},
"labels": ["Group"],
"properties": {
"name": "IMGroup",
"description": "Master group for individual members",
"since": {
"low": -661343024,
"high": 374
},
"status": "active"
}
}],
"_fieldLookup": {
"voters": 0,
"groups": 1
}
}, {
"keys": ["voters", "groups"],
"length": 2,
"_fields": [{
"identity": {
"low": 15,
"high": 0
},
"labels": ["Voter"],
"properties": {
"name_key": "ALEXANDERDWAYNEBARRINGTON",
"occupation": "AIR CON TECH",
"gender": "MR",
"street": "3 1/2 JOHNSON TERRACE",
"name": "DWAYNE ALEXANDER",
"last_name": "ALEXANDER",
"middle_name": "BARRINGTON",
"postal_code": "KGN 02",
"first_name": "DWAYNE"
}
}, {
"identity": {
"low": 23666,
"high": 0
},
"labels": ["Group"],
"properties": {
"name": "IMGroup",
"description": "Master group for individual members",
"since": {
"low": -661343024,
"high": 374
},
"status": "active"
}
}],
"_fieldLookup": {
"voters": 0,
"groups": 1
}
}, {
"keys": ["voters", "groups"],
"length": 2,
"_fields": [{
"identity": {
"low": 16,
"high": 0
},
"labels": ["Voter"],
"properties": {
"name_key": "ALLENANNETTEUNA",
"occupation": "COSMETOLOGIST",
"gender": "MISS",
"street": "28 CARNARVAN STREET",
"name": "ANNETTE ALLEN",
"last_name": "ALLEN",
"middle_name": "UNA",
"postal_code": "KGN 02",
"first_name": "ANNETTE"
}
}]
}]
console.log(records[0].get('voters').properties)