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

92
Vistas
my lastIndexOf is not working in my project
  addIngredients(ingredients: Ingredient[] | undefined) {
    ingredients?.filter(item => {
      // @ts-ignore
      console.log(this.ingredients.lastIndexOf(item.name));
      // @ts-ignore
      if(this.ingredients.lastIndexOf(item.name.toString()) === -1)
      {
        this.ingredients.push(item);
      }
    });
}

When I add items to my first time, it works but if I add duplicate items, it continues to push items in my Array.

Ultimately I am trying to prevent duplicate items from being added and update the amount if it does exist in my array.

Ingredients is a model which has 2 properties (name, amount)

export class Ingredient {
  constructor(public name: string, public amount: number) {
  }
}


export class Recipe {
  public name!: string;
  public description!: string;
  public imagePath!: string;
  public ingredients: Ingredient[] = [];

  constructor(name: string, description: string, imagePath: string, ingredients: Ingredient[]) {
    this.name = name;
    this.description = description;
    this.imagePath = imagePath;
    this.ingredients = ingredients;
  }
}
about 4 years ago · Juan Pablo Isaza
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