In a ReactJS project I have the following object array:
const arr = [
{
key1: 1,
key2: 'value1'
},
{
key1: 2,
key2: 'value2'
},
{
key1: 3,
key2: '' // empty string, therefore I do not want to pass this object in the array to be passed to the prop
}
]
And I'm passing the above array to a prop as follows:
<Component
Array={arr}
/>
Problem
I do not want to pass any object with key 'b' being an empty string (like the second object according to the example).
Is there any way that I can pass the rest of the objects as an array without the object whose key 'b' has an empty string?
arr.filter(({key2}) => !!key2)