I'm struggling to grasp the concept of arrays. I have two arrays and I want to replace the null elements in one with the elements from the other. Here is what I have currently:
var arr1 = [1,2,3,4]
var arr2 = [null, 99, null, null]
arr2.map((item) => {
if (item == null) {
arr2 = arr1.splice(item, 1)
}
})
console.log(arr2)
// The output is [3]. I was expecting 1, 99, 3, 4
I chose to use splice
as I felt it was the most appropriate method for this task. I also used .map
, but it isn't a required method.
I would appreciate any guidance to a related question that has already been answered, but I couldn't find one due to English not being my primary language.