I have an internal JSON object inside a variable:
var chessPieces = {
"p-w-1" : {
"role":"pawn",
"position":{"x":1, "y":2},
"state":"free",
"virgin":"yes"
},
"p-w-2" : {
"role":"pawn",
"position":{"x":2, "y":2},
"state":"free",
"virgin":"yes"
},...
};
And I repeat them for each cycle:
for (var piece in chessPieces){
}
How do I get the current name? For example, we are currently on the first element (piece = 0): chessPiece[piece].GiveMeTheName==>, which leads to the string "pw-1".
I really intend to pass the current element to the function because I need to check something, so it will look something like this:
function setPiece(chessPiece[piece],chessPiece[piece].position.x,chessPiece[piece].position.y){
piece.GiveMeTheName ==> which gives me string "p-w-1"
}
I also use jQuery in my project, so if something can be used there in this library, let me know.
Thanks in advance!:)
Happy source
share