Guten Abend Java Script liebe Weisen.
Habe mal wieder eine Codeblockade...
Ich möchte ein Array mit Koordinaten in einer Tabelle vom Muster Pos.x.y füllen...
Zuerst isoliere ich die x-Koordinate und y-Koordinate:
Pos = "Pos.3.3";
PositionSplit = Pos.split(".");
var x = PositionSplit[1];
var y = PositionSplit[2];
So weit so gut...
Wenn ich nun das Array nach folgendem Muster erstelle:
CompassPos = new Array (
"Pos."+(x) +"."+(y-1),
"Pos."+(x+1)+"."+(y-1),
"Pos."+(x+1)+"."+(y),
"Pos."+(x+1)+"."+(y+1),
"Pos."+(x) +"."+(y+1),
"Pos."+(x-1)+"."+(y+1),
"Pos."+(x-1)+"."+(y),
"Pos."+(x-1)+"."+(y-1)
)
Erhalte ich als Ergebnis:
Pos.3.2, (was erwünscht ist...)
Pos.31.2, (was nicht erwünscht ist, denn die X Koordinate wird als Textstring behandelt an die wegen des "+" eine 1 angehängt wird...)
Pos.31.3, (dito)
Pos.31.31,(dito)
Pos.3.31,(dito)
Pos.2.31,(dito)
Pos.2.3,(mit "-" funktioniert die Sache wieder...)
Pos.2.2 (dito)
Ich muß gestehen, daß ich etwas verwirrt bin.
Wo liegt mein Irrtum?