1
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?

1 Answer 1

1

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);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.