I am having issues where one array is greater in length than the other array for this Lab. It doesn’t seem to include the exclusive element within the larger array if one array is shorter than the other.
I was also thinking of alternative approaches. One of which checking if an element repeated more than once in the combined array, so that would be newArr. However, I don’t know how you would check such a value without a running sum or using the map data structure (which stores key value pairs). There is also the possibility of using a set, so it only stores exclusive values from both arrays but I assume the Lab doesn’t want this approach. Especially since map and set haven’t been explored in the modules.
I’m trying to push all the elements from arrayB onto the array which is stored in the newArr variable. I logged what newArr has stored to the console before I utilized the .filter() method.
It looks like your filter logic is actually on the right track, but take a closer look at how you are combining your arrays at the start.
When you use .push([...arrayB]), you might be adding the entire second array as a single nested element inside newArr instead of merging the individual items. Try checking the console.log of your newArr to see if it’s truly a flat list of items or if there’s an array inside an array.
Yeah, I just realized my mistake. I thought you could combine the elements of arrays using this approach, but I was wrong. I utilized the .concat() method instead. Thank you!
I already submitted the lab, so I am unable to experiment in the console with the code. However, would it be possible to omit the square brackets here…? Maybe that would avoid pushing the entire array as a singular element and instead push the rest of the elements of arrayB.
It returns 6 since .push() and .unshift() return the length of the newly modified array. Then it appears to show array a with the elements from its initial state along with the elements added from array b. So, it appears if you omit the square brackets then it would push each individual element from the secondary array rather than the entire array as a singular element if you included them.