Can _lodash test an array to check if an array element has a field with a certain value?

You didn’t ask for how to do it, but I assume that’s what you wanted to know.

As I already mentioned, you can use _.some, which will iterate over every element in the array and execute a callback. In that callback you can test whether the value of the topic’s property equals the value of the variable:

var result = _.some(objectiveDetail.subTopics, function (topic) {
  return topic.subTopicId === selectedSubTopicId;
});

_.some will skip the remaining elements if it found one for which the callback returned true.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)