how to skip the undefined values from the list and filter the rest of the data in react js code example

Example 1: remove null from array javascript

let array = [0, 1, null, 2, 3];

function removeNull(array) {
return array.filter(x => x !== null)
};

Example 2: how to skip the undefined values from the list and filter the rest of the data in react js

let shops = [
  {
    name: 'shop1',
    tags: ['s', 'd', 'f'],
    country: 'rda'
  },
  {
    name: 'shop2',
    tags: ['e', 'd', 'r'],
    country: 'ke'
  },
  {
    name: 'shop3',
    tags: ['p', 'u', 'i'],
    country: 'rda'
  },
  {
    name: 'shop4',
    tags: ['a', 'k', 'l'],
    country: 'bu'
  }
]

function getRdaShops(){
  retun shops.map(sh=>{
    if(sh.name && sh.country==='rda') return sh.name
  }).filter(sh=>sh!==undefined)
}

//Answer: ['shop1', 'shop3']

Tags:

Misc Example