对象中属性的拼接怎么解决undefined的问题

 const person1 = {
  name1: '小米',
  name2: ''
}
const person2 = {
  name1: '花生'
}
console.log('1111', [person1.name1, person2.name1].filter((i) => i).join('/'))
console.log('2222', [person1.name2, person2.name1].filter((i) => i).join('/'))
console.log('3333', [person1.name3, person2.name1].filter((i) => i).join('/'))
console.log('4444', [person1.name3, person2.name3].filter((i) => i).join('/'))

你可能感兴趣的:(javascript)