Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!