I want to filter array of objects in javascript. I am using filter function for it.
let data=[
{
"label": "12:00 am",
"value": 0
},
{
"label": "12:30 am",
"value": 30
},
{
"label": "1:00 am",
"value": 60
},
];
val=20;
new_data=data.filter(item=>{
return item.value>val
})
console.log(new_data)// [ { label: '12:30 am', value: 30 }, { label: '1:00 am', value: 60 } ] //expected results`
If am filtering it like
new_data=data.filter(item=>{
item.value>val;
})
without using return keyword I am getting empty array. Why do we need to use return keyword in the above example code to work? Why in case of arrays of strings we do not need return statement in the below example?
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter((word) => reword.length > 6);