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

246
Visualizações
How to compare number to sum of numbers in JS (VUE)

New to JS and VUE.

I have a variable numberOfItems in my data which has 10 as its value.

I need to compare if this value is equal to the sum of 5 different variables data

var numberOfItems = 10
var destinations = (this.campaign.shipments_ue + this.campaign.shipments_uk + this.campaign.shipments_islas + this.campaign.shipments_peninsula + this.campaign.shipments_international)

I get 22222 in destinations value instead of 10, what method should I use to sum them up so I can compare them?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Observation : Looks like you are adding a string instead of number.

If data type is string then it is resulting of concatenating strings not a number.

For Ex :

var num1 = '10', num2 = '20';
console.log(num1 + num2); // 1020 (Here both the variables are string)

num1 = 10;
console.log(num1 + num2); // 1020 (Here variable 1 is number but variable 2 is a string)

num2 = 20;
console.log(num1 + num2); // 30 (Here both the variables are number)

Now, As per your requirement. You can use parseInt() function which helps in parsing a string argument and returns an integer.

Demo :

var num1 = '10', num2 = '20';

console.log(parseInt(num1) + parseInt(num2));

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