简体   繁体   中英

Replacing existing objects in array using foreach loops javascript

I am working on array with javascript. I am able to add the array by using push. However, I am not sure how to edit an items. As you can see in this link below , I have the push method for my add item, which is working fine. But what should I do with my edit button if I want to change replacing the old item with the new one? Do I need to use foreach to do it? Help will be appreciated jsfiddle.net/hin123/tcVhN/127/

I am stuck with this part $scope.saveDetail = function (data) { //angular.foreach }

您可以使用Array.prototype.splice()插入项目,例如。

    $scope.tempData.splice($scope.tempData.indexOf(oldData), 1, newData);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM