Reputation: 8589
I am trying to turn some JS regular loops into lodash but I am getting the following error
TypeError: key.indexOf is not a function
here works properly
$scope.rows.forEach(function(row) {
for (var key in row) {
if (key.indexOf('XX') === 0) {
var value = row[key];
if (value) {
row[key] = $sce.trustAsHtml(value);
}
}
}
});
and with this way the error comes up
_.forEach($scope.rows, function(row) {
_.forEach(row, function(key) {
if (key.indexOf('XX') === 0) {
var value = row[key];
if (value) {
row[key] = $sce.trustAsHtml(value);
}
}
});
});
what am I doing wrong ?
Upvotes: 0
Views: 52
Reputation: 21249
_.forEach
calls the function with (value, key, collection)
. Use it this way:
_.forEach(row, function(value, key) {
if (key.indexOf('XX') === 0) {
...
Upvotes: 1