1

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.

Henrik
  • 673
  • 8
  • 18
  • Check this out:- http://stackoverflow.com/questions/85992/how-do-i-enumerate-the-properties-of-a-javascript-object – Rahul Tripathi Mar 16 '13 at 13:28
  • Not enough information. What is this cfd array? What does it contain? How and where is the "name" of the cfd stored? Maybe `nextFunk = c;`? – scott.korin Mar 16 '13 at 13:31
  • @Henrik: Does none of the answers work for you? – a better oliver Mar 16 '13 at 14:21
  • No, they did. I just got so captivated when I went back to coding. Although still @PSR's answer generates an error, and it sure would be nice to be able to use such clean code. Thanks for all your answers. This forum is truly amazing! – Henrik Mar 16 '13 at 16:00

5 Answers5

4
for (var c in cfd){
   if (cfd[c] <= cfd[c+1]) {
       nextfunk = c;
   }
}
makedon
  • 331
  • 1
  • 10
1

Try this:-

for (var c in cfd){
   if (cfd[c] <= cfd[c+1]) {
       nextfunk = c;
   }
}
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

try this

var value = Math.max.apply(Math, cfd);
PSR
  • 39,804
  • 41
  • 111
  • 151
  • When I try this it says "Cannot read property 'max' of undefined". Can the fact that cfd is an object, and not an array have something to do with it? – Henrik Mar 16 '13 at 13:52
0

It would be c as it contains the Name:

nextfunk = c;
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
0

Since you asked to return it:

var nextfunk;

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

return nextfunk;
SomeShinyObject
  • 7,581
  • 6
  • 39
  • 59