You try to call toLowerCase() on an Array which provides no toLowerCase() method. Instead you should specify an item in that array like:
cname = name[0].toLowerCase().replace(/ /g, ''),
This is easy to spot of you open the console of your browser as running it in Chrome gave me this message:
Uncaught TypeError: Object Abraham Lincoln,George Washington has no method 'toLowerCase'
As comments on your questions indicate you probably don't want to hard code the index of the element but instead use a loop. I tried to fiddle around with your code but it seems some input from #body is missing to get some semantic in your lines so all I can provide is one suggestion how to loop over an array of srings:
var name = ['Abraham Lincoln', 'George Washington'];
$(name).each(function(key, value){
console.log(value.toLowerCase());
});
- 2.7k
- 4
- 33
- 54