B
B
BonBon Slick2020-04-21 20:58:49
JavaScript
BonBon Slick, 2020-04-21 20:58:49

Add a return statement to this callback Sonarlint?

Object.entries(items).map(element => {
            if (commentId === element[1].id) {
                 items.splice(element[0], 1);
            }
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RAX7, 2020-04-22
@BonBonSlick

map should return some value for the new array, like:

const newArray = oldArray.map(value => {
  return value * 2;
});

what you are trying to do should probably look like this:
const idx = items.findIndex(comment => comment.id === commentId);
if (idx > -1) {
  items.splice(idx, 1);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question