Check that all items have the same value

Asked

Viewed 36 times

0

Hello, how to check if all items "estoqueLevel" has the same value ("0" in the case).

$.each(JSON.parse(response), function (i, modosEntrega) {

        for (var i in modosEntrega) {

            var foraEstoque = modosEntrega[i].estoqueLevel;

            $(foraEstoque).each(function () {

                if(foraEstoque == "0") {

                    $('.class').remove();                       

                }

            });            

        }

    });

json:

{"modosEntrega":[

  {
   "nome" : "MO00002000",
   "dias" : "2",
   "preco" : "R$ 11,00",
   "estoqueLevel" : "0"

  },
  {
   "name" : "5003",
   "dias" : "7",
   "preco" : "R$ 2,20",
   "estoqueLevel" : "0"

  }
]}

1 answer

1

From what I’ve seen of your code, you’re doing a foreach on "stockLevel", but it’s not an array, it’s within each item of the "Find Modes" array. I made a loop based on your object for you to have as reference

<script
  src="https://code.jquery.com/jquery-3.4.0.min.js"
  integrity="sha256-BJeo0qm959uMBGb65z40ejJYGSgR7REI4+CW1fNKwOg="
  crossorigin="anonymous"></script>
<script type="text/javascript">
var data = {"modosEntrega":[

  {
   "nome" : "MO00002000",
   "dias" : "2",
   "preco" : "R$ 11,00",
   "estoqueLevel" : "0"

  },
  {
   "name" : "5003",
   "dias" : "7",
   "preco" : "R$ 2,20",
   "estoqueLevel" : "0"

  }
]}
 $.each(data, function(index, item) {
   for (var i in item) {
	foraEstoque = item[i].estoqueLevel;
	if(foraEstoque == "0") {
		console.log('fora estoque');
	}
   }
 });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.