0

I have a function that is supposed to remove every json item if something, but instead removes every second one. Data is parsed json:

    {
      "idArticle": "1",
      "language": "SK"
    },
    {
      "idArticle": "2",
      "language": "SK"
    },
    {
      "idArticle": "3",
      "language": "SK"
    },
    {
      "idArticle": "4",
      "language": "SK"
    }

If we run this through my function (with let lang="x"), it removes items with ids 1 3 and keeps 2 and 4. Instead of splicing it all.

    function cutArticleList(data) {
        for (i in data) {
            if (data[i].language === lang.toUpperCase()) {
                continue;
            } else {
                data.splice(i, 1);
            }
        }
        res.send(data);
    }

0 Answers0