Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

This question already has an answer here:

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.

share|improve this question

marked as duplicate by charlietfl angularjs 14 hours ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Can you provide us some example in plunker or jsfiddle? – the scion 14 hours ago
up vote 1 down vote accepted

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'
share|improve this answer
    
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 14 hours ago
    
You are welcome. It's awesome that I can help you. I'm not Indian, I'm Bangladeshi. – sabbir 14 hours ago
    
thanks brother. – Prashant Shukla 5 hours ago
$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;

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.