I am learning to filter nested arrays in javascript and I believe this example can help me to understand it better. below is the object.
const game = () => {
return {
player1: {
username: 'ABC',
playingAs: 'X'
},
player2: {
username: 'XYZ',
playingAs: '0'
},
board:
[
['✓', null, 'X'],
['X', '✓', null],
['✓', null, 'X']
]
}
};
my code is below
const {player1: {username: PlayerA, playingAs:PlayerAMark}, player2: {username: PlayerB, playingAs:PlayerBMark}} = game();
const {board: board} = game();
//is there any efficient way to do it without a loop using a filter?
for (const item in board) {
//One approach which comes to my mind is to loop. but that is what I don't think would be a learning curve for me.
}
I am trying something like this
const array = board;
for (const item in board) {
console.log(array.filter(innerArray => innerArray[item] !== 'X'));
}
I am focused on implementing some efficient way that can help me to return
Player1 marked 'X' at 3,1,3 and
Player 2 marked '0' at location at 0,2,1
I am only stuck with filtering this board multidimensional array.
I appreciate your help on this.