I am looping through a object, and conditionally i am consoling the result. but i am getting all the 3 result, instead to get just 2. what is wrong with my code?
Any suggestion please?
my code :
var processModules = function (mData) {
var lcalmData = obj = {'content':'new content','navigation':'newNavigation','form':'newform'}; var title;
$('body').append(
$.each(lcalmData, function (i,val) {
title = (i === 'content' || i === 'navigation') ? $('<div />') : i === 'form' ? $('<form />') : null;
return title;
} )
)
}
This line is problematic:
val === 'content' || 'navigation'I suppose you meant to check whether
valis equal to one of these values? ) But it doesn’t work this way: as===operator priority is higher than||one, it’s essentially the same as…(val === 'content') || 'navigation'… in other words, always a truthy value.
What you intended may be rewritten just as simple as…
... (i === 'content' || i === 'navigation')… as it’s the index (key) that should be checked, not value.