I am creating a JavaScript array is the following manner:
var selectedColors= { 'Orange' : $("#Orange").val(), 'Light Blue' : $("#LightBlue").val(), 'Dark Red' : $("#DarkRed").val(), 'Dark Blue' : $("#DarkBlue").val()}; Then loop through each item to see which color was not selected, and then store them in another array:
var colorsNotSelected = []; $.each(selectedColors, function (key, value) { if (value.length == 0) colorsNotSelected.push({key:key}); }); Here I want to display the colors not selected, but doing it the following way display the keys: 0,1,2,3 instead of Orange, Light Blue, Dark Red, Dark Blue.
What am I doing wrong here?
if (colorsNotSelected.length > 0) $.each(colorsNotSelected, function (key) { alert(key) }); return false; Any help is much appreciated.