Prashant Shukla Prashant Shukla - 2 years ago 67
AngularJS Question

Assign dynamic index in array of object in Angularjs

If I have array of object in such a way.

data[0].name= 'Prashant Shukla';
$scope.getColumn[i].Field = 'name';

Using above I want to assign
in dynamic way. I have try like this

$scope.getColumn[i].value = data[0].+$scope.getColumn[i].Field;

but this give me
Uncaught SyntaxError: Unexpected token +

I can get
Prashant Shukla
but How can I get exactly same by using
in place of
index ?

how can I resolve this error and assign value dynamically?

thanks ahead.

Answer Source

you can use as like as given below:

data[0].name= 'Prashant Shukla';
$scope.getColumn[i].Field = 'name';

console.log( data[0][ $scope.getColumn[i].Field ] );  // 'Prashant Shukla'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download