Assessment wanted for "Test your skills:Arrays" question #3

Chris (I presume),

Looking for assistance.

Link to what I have so far: https://jsfiddle.net/cazzimoto/s0rfvtyz/8/

Link to what I believe will work for solution: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_foreach

  • I even edited the code from w3scho… mixing item and index and added (index) and got the desired result!

I am having trouble connecting the dots between the two.

Thank you in advance for you help. It is MUCH appreciated!

V/R,
cazzimotto

@cazzimoto hi there!

Yes, you are definitely right that forEach() will help you here. Inside the forEach() callback, you’ve got the array item and its index value made available.

One problem is that the array values inside forEach() are not “live”, meaning that if you change the value with something like item = newValue, it won’t work.

The item is only a copy of the item in the array, rather than the actual item in the array, if that makes sense? So instead, you’ll have to create the new value for the array item, and then copy it back to the actual array with something like myArray[index] = newValue.

Let me know if that helps. Good luck!

@ chrisdavidmills

Thank you for the reply!

I am still having issue finding the solution. I have tried an assortment of solutions, all of which have not produced the desired outcome. The best of what I have put together follow:

let last = myArray.pop();
myArray = myArray.push(‘Fei Long’, ‘Balrog’);

for (let 1 = 0; i < myArray.length; i++) {
let breaker = myArray[i].split(’,’);
let name = breaekr[0];
let index = breaker[2];
let finalArray = name + ‘-’ + index;
let list = finalArray.toString;
}

AND THIS TO TEST:
let last = myArray.pop();
myArray = myArray.push(‘Fei Long’, ‘Balrog’);

myArray.forEach((myArray, index) ==> {
console.log(myArray, index);
});

Again, thank you for your assistance.

V/R,
cazzimoto

Hi @cazzimoto! Nice try, but yeah, you’re getting a bit confused here. Have a look at marking guide for this one, so you can check out what we did: https://github.com/mdn/learning-area/blob/master/javascript/introduction-to-js-1/tasks/arrays/marking.md#task-3