I’m trying to log to console whether an array of objects contains a specific value on a specific attribute of one of these such objects.
in Python this is as simple as
print(val in [x['attribute'] for x in objects])
In JS, I think the inclusion operation should function as
objects.map(x=>x.attribute).includes(val);
// console.log(objects.map(x=>x.attribute).includes(val).toString());
From reading, I’ve come to understand that raw booleans cannot be logged so they must be converted to string first.
the above is neither logging "true" or "false". So am I doing something wrong?
>Solution :
Your code is correct if you want to log whether an array of objects contains a specific value on a specific attribute of one of these such objects.
Whether the object contains a value returns a boolean.
Are you trying to log the objects that have an attribute that contain a specific value? If so, I would use filter in stead of map, like this:
objects.filter(x => x. attribute.includes(val)).