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

Hello readers! In this post I have shared the details about “how to skip the undefined values from the list and filter the rest of the data in react js”. Okay, let’s move on to the post.

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

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

function removeNull(array) 
return array.filter(x => x !== null)
;
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']

Final Words

I hope this article helps you to know about “how to skip the undefined values from the list and filter the rest of the data in react js”. If you have any questions regarding this post please let us know via the comment section. Share this article with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment