Return an object from a function

Tell us what’s happening:
Describe your issue in detail here.
Greetings everyone,
am try to build an alarm clock and i have a function that takes two params id and an array of objects when the alarm is to be edited and i expect this same function to return an object containing the details of the alarm in question.
But i keep getting a type

  **Your code so far**
function editTimer(id, timer) { => {
    const targetItem =;
    const values = Object.values(item.editValue)
    if (targetItem === id) {
      inputDigit.forEach((i, index) => {
        i.value = format(values[index]);
      return item.editValue;



I don’t see where the editTimer function is returning anything, which means it returns undefined by default. The return statement you currently have is for the map method, not the editTimer function.

I’m not exactly sure what you are trying to return here, but it sounds like it should be an object, not an array, so I’m not sure the map method is what you want to use here. If you just need to go through the array of objects passed in and find the one that has the matching id so you can do something with it and return it then there are probably better methods to use, perhaps find.

Hello everyone,
Ahh… this how the project looks like, Once a new alarm is created there is an array called timer that receives an object of values as such
{ id, actualValues:{hour:0, min:0, sec:0}, editValue:{hour:0, min:0, sec:0}} for each alarm that is created. After an alarm is created , it can then be edited using the edit button. so the function editAlarm (changed the previous name and a few details) is expected to return the object editValues for that particular alarm which is to be edited. This is what i came up with but am still getting undefined

  • timer is a global variable;
  • id is obtained from the alarm after hitting edit button

The properties of the returned object are then displayed in the modal fields as shown as hour:min:sec in the image below for editing as of now nothing is being displayed cause am not returning from this function.

function editAlarm(id, timer) {
  let item = timer.find(item => {
    const targetItem =;
    const valuesToEdit = Object.values(item.editValue)
    if (targetItem === id) {
      return values
  return item;

Thanks a lot,
i have tried array.find() , changed a couple of variable names and am getting the output i desire

function editAlarm(id, alarms) {
  const result = alarms.find(alarm => === id)
  return result.editValue;

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.