Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery loop conditional statement

How do I write a conditional statement for a jquery $.each loop? I tried to follow the suggestions at Is there conditional looping with $.each function in jQuery and other posts, however, I couldn't get it to work:

$.each((rgJson1["release-groups"]), function(index, item) {  

var workTitle = item.title;
var pType = item['primary-type'];
var frDate = item['first-release-date'];

if (pType = "Album") {

console.log(workTitle);

}

});

When I tried that, it set the pType variable to "Album". So, I tried:

if (item['primary-type'] = "Album") {

console.log(item.title);

But it still didn't work. I also tried a variety of different combinations of brackets, quotes, and the like, but I haven't found a solution.

like image 337
user3080392 Avatar asked Sep 24 '26 16:09

user3080392


1 Answers

try the following

if (item['primary-type'] === "Album")

or

if (pType === "Album")

using just a single '=' will set the value, using '===' will check for congruency

like image 187
Liam Schauerman Avatar answered Sep 26 '26 05:09

Liam Schauerman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!