I have an array that contains objects that looks like this.
const arr = [
{
value: -1,
label: "None"
},
{
value: 24*60*60,
label: "24 hours"
},
{
value: 7*24*60*60,
label: "7 days"
},
{
value: 30*24*60*60,
label: "1 month"
},
{
value: 90*24*60*60,
label: "3 months"
}
];
I have the below function which 'kind of' works, but it is not returning the value. Can anyone spot what I am doing wrong?
The following is a react method
class Test extends Component {
......
getLabelFromValue(arr, value) {
arr.forEach((item) => {
if(item.value === value) {
return item.label;
}
});
}
const value = getLabelFromValue(arr, 86400); //value is equal to undefined
getLabelFromValue(arr, value) {should befunction getLabelFromValue(arr, value) {forEachand notmapand not returning anything frmgetLabelFromValue?