0

I have the following block of code:

      <div className="max">
        {Math.max.apply(
          Math,
          items.feeds.map(function(o) {
            const temp = 34;

            if(o.field1 <= temp) {
              return <b>{o.field1}</b>; //return NaN
             }
            else {
               return o.field1;
            }

          })
        )}
      </div>

However, the if statement returns NaN. If I just return o.field1, it works. Like this:

items.feeds.map (function (o) {return o.field1}

Is there an issue in my if statement? I want if the value of o.field1 satisfies the condition when printing to screen it is bold.

1
  • Use filter instead Commented Nov 1, 2018 at 8:08

1 Answer 1

1

Math.max returns a number:

Return value: The largest of the given numbers. If at least one of the arguments cannot be converted to a number, NaN is returned.

What you return is <b>{o.field1}</b> - it cannot be converted to a number. Wrap returned number with <b> tags later.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.