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.

1
  • Can you provide us some example in plunker or jsfiddle? Commented Jun 5, 2016 at 18:45

2 Answers 2

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'
Sign up to request clarification or add additional context in comments.

2 Comments

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 :-)
You are welcome. It's awesome that I can help you. I'm not Indian, I'm Bangladeshi.
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;

5 Comments

Because I have fetch data in array of object format.
I think you are not getting what I want to ask. please read again my question.
But this syntax is not make sense... you can't write data[0].+
Definitely this syntax not make sense but How can I write?
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.