我有一个如下的javascript数组:

$scope.products = [
    {id:'1', name:'IPhone6', price: '1,000 AED', quantity: '2'},
    {id:'2', name:'Samsung Mini', price: '750 AED', quantity: '1'},
    {id:'3', name:'Dell Laptop', price: '1700 AED', quantity: '3'},
    {id:'4', name:'HCL Monitor 7"', price: '650 AED', quantity: '7'},
];


使用ng-repeat Angular js函数在数组上方显示。

我正在调用remove函数并将id作为参数传递。如何从数组中删除特定元素?

不需要$scope.products.slice($id, 1)。我必须删除ID吗?请指教。

最佳答案

这应该工作:

// id = '3'

$scope.products = $scope.products.filter(function (p) { return p.id !== id });

10-08 08:45
查看更多