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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -