I try to check if an array of object has a key value pair with the key service_tags
and a value of an array
including the string "trace"
. If this array has it, I also want to return the position of the object.
My try returns undefined
.
gg.fields =
[
{ ... },
{value: "D", display_name: "Nat."},
{
"value":"Likes redwine",
"display_name":"Trace 2",
"servicio_tags":[
"trace"
]
}
]
//function
let traceFieldExists = gg.fields.forEach((field, positionOfTraceField) => {
if (field.servicio_tags && field.servicio_tags[0] === 'trace') {
return {
positionOfTraceField : positionOfTraceField,
exists : true
};
} else {
return {exists : false};
}
});
Thanks for the help!