Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

81
Visualizações
Trying to understand some basic Javascript logic
const nums = [1, 50, 75, 200, 350, 525, 1000];
const smallerNums = nums.map(num => num - 5);
console.log(smallerNums);

Hello, Javascript newb here. The above is taken from CodeAcademy. I just want to make sure I understand the basic logic here:

Is this saying the new array 'smallerNums' is built when 'num - 5' is returned. The parameter num, is what is 'iterating' through the established array nums, to identify each element, then for 'num - 5' to take this value, subtract five and hence find a new value which will appear in the smallerNums array.

Terminal, btw :

[
   -4,  45,  70, 195,
  345, 520, 995
]
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Yes, map() creates a new array based in the function call on every element the original array as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map mentions.

So what it does is just run the function you create on every element.

about 4 years ago · Juan Pablo Isaza Relatório

0

Yes you are basically mapping the value of nums array subtracted by 5 to a new array which is smallerNums.

map() creates a new array from calling a function for every array element.

about 4 years ago · Juan Pablo Isaza Relatório

0

Actually, map() creates a new array. one more thing these two arrays "nums" and "smallerNums" are completely separate from each other, and by separate I mean if you change either element of "nums" or "smallerNums" the other array stays intact.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda