I have an array which contains on the left side of the colon, the name of the level, whilst on the right side, it has the difficulty the level has been completed on.
I want to be able to put this into objects within an array so that later on when I need to check which levels have been completed on the difficulties, I can go to each object in the array to check.
Below is the array I have currently:
var levels = [
"Level 1 : Easy",
"Level 1 : Normal",
"Level 1 : Hard",
"Level 2 : Easy",
"Level 2 : Normal",
"Level 3 : Easy",
"Level 3 : Hard"];
How could I put this into objects within an array so it is like this:
var levelCompletion = [
{
name: "Level 1",
easy: true,
normal: true,
hard: true
},
{
name: "Level 2",
easy: true,
normal: true,
hard: false
},
{
name: "Level 3",
easy: true,
normal: false,
hard: true
}
];
Please note that the "levelCompletion" array already exists in my project, however all difficulty values are set to false since I am failing to grasp how I can put the values in the "levels" array into the "levelCompletion" array correctly.
Many thanks
levelsis an Array ofStringand not Array ofObjectright?