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.
try the following
or
using just a single '=' will set the value, using '===' will check for congruency