Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda