Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10935 closed bug (worksforme)

isNumeric return true on array with only one numeric value

Reported by: mengsoon Owned by:
Priority: low Milestone: None
Component: misc Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


isNumeric return true when the test value is an array with only one numeric value.

eg: $.isNumeric([1,2]) will return false, but $.isNumeric([1]) will return true instead of false.


Change History (4)

comment:1 Changed 5 years ago by sindresorhus

  • Component changed from unfiled to misc
  • Priority changed from undecided to low
  • Status changed from new to open

Confirmed in Chrome 15 and Firefox 8.

This is because the isNumeric method is using parseFloat which is coercing the array into a number.

comment:2 Changed 5 years ago by gibson042

Can we just update the isNumeric documentation to make it clear that what's being checked is the argument's String representation?

comment:3 Changed 5 years ago by rwaldron

  • Resolution set to worksforme
  • Status changed from open to closed

What is there to change? That behaviour is correct. http://es5.github.com/#x15.1.2.3

comment:4 Changed 5 years ago by sindresorhus

@rwaldron can't we at least just add this to the other examples, to make it clear? $.isNumeric("[1]");   true

Note: See TracTickets for help on using tickets.