Henrik
Henrik

Reputation: 703

How do I return a property name?

Im not quite sure how to do this, or what to google to find the answer...

for (var c in cfd){
   if (cfd[c] <= cfd[c+1]) {
       nextfunk = ???
   }
}

After the for-loop thing I want nextfunk to have the value of the name of the lowest valued cfd.

Thanks.

Upvotes: 1

Views: 98

Answers (5)

SomeShinyObject
SomeShinyObject

Reputation: 7821

Since you asked to return it:

var nextfunk;

for (var c in cfd){
   if (cfd[c] <= cfd[c+1]) {
       nextfunk = c;
   }
}

return nextfunk;

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172578

Try this:-

for (var c in cfd){
   if (cfd[c] <= cfd[c+1]) {
       nextfunk = c;
   }
}

Upvotes: 1

Vishal Suthar
Vishal Suthar

Reputation: 17194

It would be c as it contains the Name:

nextfunk = c;

Upvotes: 0

makedon
makedon

Reputation: 331

for (var c in cfd){
   if (cfd[c] <= cfd[c+1]) {
       nextfunk = c;
   }
}

Upvotes: 4

PSR
PSR

Reputation: 40338

try this

var value = Math.max.apply(Math, cfd);

Upvotes: 0

Related Questions