Reputation: 123
I have the following code:
var nowa = [];
var tab = [{'material':'221214', 'item':'SPRITE 0,33LX24PUS', 'quantity':'2', 'jedn':'CS'}];
$.each(tab, function(index, w) {
if(($.inArray(w.material, nowa)) == -1){
nowa.push(w.material);
if(w.item == '0,33')
rodzaj = 'can';
if(w.item == '0.5')
rodzaj = 'pet';
$('table.new').append('<tr class="'+w.material+'" id="'+rodzaj+'"><td>'+w.material+'</td><td>'+w.item+'</td><td class="qq">'+w.quantity+'</td><td>'+w.jedn+'</td></tr>');
}
});//each
How to compare w.item with other text in this case?
Because this:
if(w.item == '0,33')
rodzaj = 'can';
is not working.
w.item values can be: 0,5 0.5 0.33 1,0 1.5 2,5 and other.
Upvotes: 1
Views: 842
Reputation: 87073
You can use
w.item.search('0,33')
So your comparison will look like
if(w.item.search('0.33') >= 0) {
roadzaj = 'can';
}
Read more about .search()
If search become successful,
search()
returns the index of the searched element inside the string. Otherwise, it returns -1.
Upvotes: 2