1

I am passing my string to the below function.

$scope.sort= function(query){
    console.log(query); // results "name";

    $scope.resultset.sort(function(a, b) {
    return parseFloat(b.query) - parseFloat(a.query);  //results undefined;
    });
};

where b and a are my objects in resultset Array.

How to find the props in obj with variable name?

Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
  • Are `a` and `b` string objects?.. You cannot append dynamic properties to strings in javascript. http://stackoverflow.com/a/5201148/2300466 – Ahmad Ibrahim Jun 12 '15 at 07:50

1 Answers1

0

I suppose you mean accessing an object property with a dynamic name.

In javascript, you can access any object propert with an array-like notation:

b.query

is equivalent to :

b["query"]

So you could do :

var property = "query";
var value = b[property];
Remy Grandin
  • 1,638
  • 1
  • 14
  • 34