How to check for the presence of certain strings in JSON, for example:
{ "id": "4", "name": "Weissgold-Verlobungsring mit Diamanten", "image": "/images/content/white-gold1.jpg", "oldprice": "14 500 €", "newprice": "16 100 €", "discount": "-10%" }, { "id": "5", "name": "Gold-Verlobungsring mit Diamanten", "image": "/images/content/white-gold2.jpg", "oldprice": "110 500 €", "newprice": "16 100 €", "hit": "hit" }, { "id": "6", "name": "Ring zur Verlobung mit Diamanten", "image": "/images/content/white-gold3.jpg", "oldprice": "110 500 €", "newprice": "16 100 €", "new": "new" }, { "id": "7", "name": "Ring zur Verlobung mit Diamanten", "image": "/images/content/white-gold1.jpg", "oldprice": "110 500 €", "newprice": "16 100 €" }, { "id": "8", "name": "Ring zur Verlobung mit Diamanten", "image": "/images/content/white-gold3.jpg", "oldprice": "110 500 €", "hit": "hit" } There is a discount, how to check for its availability?
$(document).ready(function(){ $('.b-pagination__link--more').click(function(){ // вешаем на клик $.ajax({ url: 'json/product.json', //url: '/ajax/review.php', method: 'GET', dataType: 'json', success: function (json) { if (json['product'].length > 0) { var product = json['product']; $.each(product, function (id, data) { // console.log() var html = '<a href="#" data-product-id="' + data.id + '" title="" class="b-list-product__item col-md-3 col-sm-4 col-xs-6">\ <div class="b-list-product__link">\ <div class="b-list-product__background"></div>\ <div class="b-list-product__quick-preview">\ <span class="b-button-color b-list-product__link-preview">Übersicht</span>\ </div>\ </div>\ <img src="' + data.image + '" alt="" title="" class="b-list-product__image">\ <p class="b-list-product__info">' + data.name + '</p>\ <p class="b-list-product__price">' + data.newprice + '</p>\ <div class="b-list-product__old-price">\ <p class="b-list-product__old">' + data.oldprice + '</p>'; if (parseInt(data.discount) > 0) { html += '<div class="b-sale b-sale--list-product">' + data.discount + '</div>'; } html += '</div>\ </a>'; $('.b-list-product__item:last-child').before(html).parent('.b-list-product--catalog'); }); } } }); }) }); I tried this option
if (parseInt(data.discount) > 0) { html += '<div class="b-sale b-sale--list-product">' + data.discount +</div>'; } But does not work!