I have a statement:
var sep = ' | ';
var r = '';
for (var i = 0; i < menuItems.length; i++) {
r += function(menuObject) {
console.log(menuObject);
console.log(
'<a class="" href="' +
menuObject.url + '">' + menuObject.name + '</a>' +
(i < menuItems.length - 1) ? sep : ""); //logs the contents of sep
) //console.log expanded for readability
}
}
Why is it not logging the full string, and instead only evaluating to sep?
Because you are not wrapping your if line in parenthesis and it is process all of the string before it as the condition.
Try this…