0

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 Prashant in $scope.getColumn[i].value 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 by data[0].name but How can I get exactly same by using $scope.getColumn[i].Field in place of name index ?

how can I resolve this error and assign value dynamically?

thanks ahead.

Prashant Shukla
  • 241
  • 1
  • 5
  • 21

2 Answers2

1

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'
sabbir
  • 2,020
  • 3
  • 26
  • 48
  • thanks Sabbir. It works. Well I think you are Indian and this is mid night for indian time. I am very happy to see you are working in this time :-) – Prashant Shukla Jun 05 '16 at 18:58
  • You are welcome. It's awesome that I can help you. I'm not Indian, I'm Bangladeshi. – sabbir Jun 05 '16 at 19:18
0
$scope.getColumn[i].value = data[0].+$scope.getColumn[i].Field;

Why you have . after the data[0]?

It should be data[0].name +$scope.getColumn[i].Field;

The scion
  • 1,001
  • 9
  • 19