I have this code:
var app = {
items: [
[{
title: 'Overview',
id: 'dashboard'
}, {
title: 'Reports',
id: 'reports'
}],
[{
title: 'Customers',
id: 'customers'
}, {
title: 'Quotes',
id: 'quotes'
}, {
title: 'Sales',
id: 'sales'
}],
[{
title: 'Suppliers',
id: 'suppliers'
}, {
title: 'Purchases',
id: 'purchases'
}],
[{
title: 'Bank',
id: 'bank'
}, {
title: 'Projects',
id: 'projects',
disabled: true
}, {
title: 'Journal',
id: 'journal',
disabled: true
}]
]
}
var userDetails = {
IsAdmin: true
};
for (var x = 0; x < app.items.length; x++) {
app.items[x].filter(function (items) {
if (items.disabled || (userDetails.IsAdmin && items.id !== 'quotes')) {
var ind = app.items[x].indexOf(items);
app.items[x].splice(ind, 1);
}
});
}
console.log(app.items);
The output is that there is 1 object left in each array by the end. This is not desired, by my calculations, there should just be a single object left (the quotes object),
related jsFiddle: http://jsfiddle.net/UdzEW/
Any ideas?