Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  99] [ 4]  / answers: 1 / hits: 39670  / 9 Years ago, mon, september 28, 2015, 12:00:00

I have arrays such as



var arrayVal_Int = [21, 53, 92, 79];   
var arrayVal_Alpha = [John, Christine, Lucy];
var arrayVal_AlphaNumeric = [CT504, AP308, NK675];



  • Above arrayVal_Int should be considered as (purely) numeric.

  • arrayVal_Alpha and arrayVal_AlphaNumeric should be considered as strings.



I need to check that in JavaScript.


More From » arrays

 Answers
14

Shortest solution, evals to true if and only if every item is (coercible to) a number:



!yourArray.some(isNaN)

[#64917] Thursday, September 24, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeffn

Total Points: 559
Total Questions: 81
Total Answers: 103

Location: Spain
Member since Thu, Dec 23, 2021
2 Years ago
;