javascript - TypeError: first.value is undefined -


i tried running code , can not understand why error 'typeerror: first.value undefined', should arise in use-case highlighted below:

function myfunction() {   var str = "aust988957588raliajfur748jejfu3737238ef8re8e";   var res = str.split("");    var first = res[0];   var = /^[a]$/;    if (first.value.match(a)) {     alert("a");   } else {     alert("false");   } } 

a careful review of reosource https://developer.mozilla.org/en-us/docs/web/javascript/reference/errors/unexpected_type did not help.

what issue causing error?

first string "a", string doesn't have value property, returns undefined. use first.match(a):

function myfunction() {   var str = "aust988957588raliajfur748jejfu3737238ef8re8e";   var res = str.split("");    var first = res[0];   var = /^[a]$/;    if (first.match(a)) {     alert("a");   } else {     alert("false");   } } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -