Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  13] [ 5]  / answers: 1 / hits: 25207  / 12 Years ago, tue, january 22, 2013, 12:00:00

If i had an array of days names and i wanted to check for example if sunday - first letter capital or small - in this array what would be the best thing to do ?


More From » javascript

 Answers
18

You may also use Array.indexOf:



var days = [monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday];

function isInArray(days, day) {
return days.indexOf(day.toLowerCase()) > -1;
}

isInArray(days, Sunday); // true
isInArray(days, sunday); // true
isInArray(days, sUnDaY); // true
isInArray(days, Anyday); // false


Check the browser compatibility in MDN.


[#80706] Monday, January 21, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hasancolec

Total Points: 603
Total Questions: 95
Total Answers: 98

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;