Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery $.inArray is not working with ASCII characters

Tags:

html

jquery

As you can see in jsfiddle , I have taken two black coins. If I place a black coin on another black coin then it should show alert that "can't kill your own kind" and place the coins in their previous positions. But as you can see it is not working.

like image 508
Mr_Green Avatar asked Nov 03 '22 16:11

Mr_Green


1 Answers

I think your problem is that you're looking for an HTML Entity Encoded version of your UTF-8 characters. HTML Entity Encoding uses the form &#XXXX;, where XXXX is the decimal value of the entity (in this case, a UTF-8 character code).

On the JavaScript side, you need to be using the JavaScript form of the entity, which is \uXXXX, where XXXX is the hexadecimal value of the entity. So by converting your decimal values to hex and putting them in the proper form, your search array should be:

var blackCoins = ["\u265b", "\u265c"];

I'm not sure how the game is supposed to work, but making this change does result in "matches" from $.inArray(). So I think that's what you're looking for.

like image 111
Pete Avatar answered Nov 08 '22 04:11

Pete