How to join two values of an array into one?

Asked

Viewed 20 times

1

For example: If I have an array that stores the hours and another array that will store the minutes

const arrayHora = [10]
const arrayMinuto = [53]

How would you join the two values of the arrays together to be = [1053] or = [10:53]

  • This arrayHora/arrayMinuto will always have a single position?

  • They will only have one position. Since it is only 1 input (actually 1 HOUR and 1 MINUTE)

  • Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.

  • If each array will contain only one position, it makes no sense to use arrays. Anyway, if you really need to use arrays, you can also do it as follows: [...arrayHora, ...arrayMinuto]. Join(':')

1 answer

1

From what I understand, you intend to access the variable of each array and "mount" a time.

const arrayHora = [10]
const arrayMinuto = [53]

var horario = arrayHora[0] + ":" + arrayMinuto[0]

console.log(horario)

Remembering:

  • The horary becomes a string variable in this case.
  • Use "[0]" where 0 is the index of the array, so if the array is larger, you can iterate/access directly by the index number of the array.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.