i have an array of objects like below,
const arr_obj = [
{
id: '1',
jobs: [
{
completed: false,
id: '11',
run: {
id: '6',
type: 'type1',
},
},
{
completed: true,
id: '14',
run: {
id: '17',
type: 'type1',
},
},
{
completed: false,
id: '12',
run: {
id: '7',
type: 'type2',
},
},
],
},
{
id: '2',
jobs: [
{
completed: true,
id: '13',
run: {
id: '8',
type: 'type2',
},
},
{
completed: true,
id: '16',
run: {
id: '9',
type: 'type1',
},
},
{
completed: true,
id: '61',
run: {
id: '19',
type: 'type1',
},
},
],
},
{
id: '3',
jobs: [
{
completed: false,
id: '111',
run: {
id: '62',
type: 'type1',
},
},
],
},
],
and an arr_ids = ["1","2"]
now i have to filter those ids from arr_obj matchings arr_ids which i do like so
const filteredIds = arr_obj.filter(obj => arr_ids.includes(obj.id));
so the filtered_arrobj = [
{
id: '1',
jobs: [
{
completed: false,
id: '11',
run: {
id: '6',
type: 'type1',
},
},
{
completed: true,
id: '14',
run: {
id: '17',
type: 'type1',
},
},
{
completed: false,
id: '12',
run: {
id: '7',
type: 'type2',
},
},
],
},
{
id: '2',
jobs: [
{
completed: true,
id: '13',
run: {
id: '8',
type: 'type2',
},
},
{
completed: true,
id: '16',
run: {
id: '9',
type: 'type1',
},
},
{
completed: true,
id: '61',
run: {
id: '19',
type: 'type1',
},
},
],
},
]
Now i will have to get the ids from filtered_arrobj whose runs are of type "type1" and none of the jobs have completed: false.
so the expected output from filtered_arrobj is "2"
here in the above example id "1" is not taken because id "1" has job completed: true but it also has job completed: false for type "type1".
what i have tried?
const output = filtered_arrobj.map(obj => obj.jobs.map(job => job.run.type ===
"type1" && job.completed === true));
when i log the output its gives like so
[
[false,true,false],
[true,true,true]
]
this not giving me the id of the obj whose job has run of type = "type1" and which has no jobs completed: false.
how can i get that. could someone help me with this. I am new to programming and learning on the go. thanks.