Reputation: 31
var string1 = "Hello, World";
var arr = string1.split(",");
var string2 = "Hello World";
How do I compare the value of the arr
array with the value of the variable string2
?
Upvotes: 1
Views: 48
Reputation: 1531
Just use join
method as below:
var string1 = "Hello, World";
var arr = string1.split(",");
var string2 = "Hello World";
var arr_string = arr.join('');
console.log(arr_string == string2);
Or you could try replace
as below:
var string1 = "Hello, World";
var string2 = "Hello World";
var new_string1 = string1.replace(/,/g, '');
console.log(new_string1 == string2);
Upvotes: 1