Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<div>
Countries: <br/> {{countries | json}}!
</div>
<div>
<hr/>
<input ng-model="path" />
<button ng-click="remove()">Exe</button>
</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.countries = {
countries: {
canada: {
area: 3855000,
capital: "ottawa",
territories: {
alberta: {
area: 255451,
capital: "edmonton"
},
yukon: {
area: 186272,
capital: "yellowknife"
}
}
},
usa: {
area: 3806000,
capital: "Washington",
territories: {}
}
}
}
$scope.path = "countries.canada.territories.yukon";
$scope.remove = function () {
var pathInArrayForm = $scope.path.split('.');
currentObject = $scope.countries;
for (var i = 0; i < pathInArrayForm.length; i++){
currentObject = currentObject[pathInArrayForm[i]];
}
currentObject.capital = "Montreal";
}
}