I received the following object:
[
{
"name": "Test",
"settings": {
"object": {
"hoursAvailable": [
11,
9,
14
],
"value": 65
}
}
},
{
"name": "Test 2",
"settings": {
"object": {
"hoursAvailable": [],
"value": 65
}
}
},
{
"name": "Test 3",
"settings": {
"object": {
"value": 65
}
}
}
]
I am currently trying to figure out how to remove all instances where hourAvailable is less than 10, utilizing .filter or lodash. The issue arises when there are undefined "hoursAvailable" objects. After applying the filtering process, my desired output should be as follows:
[
{
// other data
"settings": {
"object": {
"hoursAvailable": [
9, // <- all numbers <10
],
"value": 65
}
}
},
{
// other data
"settings": {
"object": {
"hoursAvailable": [],
"value": 65
}
}
},
{
// other data
"settings": {
"object": {
"value": 65
}
}
}
]
Currently, I have attempted the following approach:
.filter(arr => {
arr['settings']['object']['hoursAvailable'] <= 10;
}
However, this results in undefined values when there are no 'hoursAvailable' objects and fails to delete numbers less than 10 in ['hoursAvailable']. What steps should I take to adequately remove numbers less than 10 in ['hoursAvailable']?