Why function getPrice('Table') doesn't work in controller? It return undefined instead 400. That quite works in plain JS (without $scope).
function MyCtrl($scope) {
$scope.prices = [{
name: 'Bed',
price: 900
}, {
name: 'Table',
price: 400
}];
$scope.getPrice = function (name) {
$scope.prices.forEach(
function (el) {
if (el.name == name) {
return el.price;
} else {
return null;
}
}
);
}
};