2021年1月19日星期二

javascript merge 2 arrays with undefined elements

Hello I need a little help with js i have 2 arrays

const a = ['link1','link2,'link3','link4','link5']  const b = ['link11','link22',undefined,'link44',undefined]  

how can I replace the elements of a with b with ignoring the undefined index so the output would be

a = ['link11','link22','link3','link44','link5']   

I tried to do it like this

  Array.prototype.splice.apply(      a,      [0, b.length].concat(b)    );  

but I got the array b back

https://stackoverflow.com/questions/65802833/javascript-merge-2-arrays-with-undefined-elements January 20, 2021 at 11:49AM

没有评论:

发表评论