javascript - Merge two string arrays excluding some values -


i have 2 arrays:

var = ['a123', 'a321', 'a444', 'b3132', 'a123']; var b = ['b3132', 'a321', 'a444', 'a123', 'a123']; 

and want merge them condition , value not on array, when character 'b' on string , ignore , proceed merge, result be:

var ab = ['a123', 'a321', 'a444']; 

i have solved on loop checking array values 1 one think there's better solution.

an es6 solution - use set() unique items, spread, , filter array remove items include b. if b 1st letter in string use string.prototype.startswith() instead of array.prototype.includes().

const = ['a123', 'a321', 'a444', 'b3132', 'a123'];  const b = ['b3132', 'a321', 'a444', 'a123', 'a123'];    const result = [...new set(a.concat(b))].filter((item) => !item.includes('b'));    console.log(result);


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -