Answers for "how to skip the undefined values from the list and filter the rest of the data in react js"

4

remove null from array javascript

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

function removeNull(array) {
return array.filter(x => x !== null)
};
Posted by: Guest on June-19-2020
0

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']
Posted by: Guest on May-31-2021

Code answers related to "how to skip the undefined values from the list and filter the rest of the data in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language