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

175
Views
¿Cómo obtener el valor del objeto de una matriz en el almacenamiento local y compararlo con un nuevo valor?

Estoy tratando de guardar un objeto en una matriz en el almacenamiento local,

pero primero quiero verificar si el objeto ya existe o no comparando el Título existente en el almacenamiento local con el título del nuevo objeto. Pero no sé cómo hacerlo.

 const RecipeList = ({recipe}) => { const setData = () => { const newTitle = recipe.label; const existedFavRecipe = JSON.parse(localStorage.getItem('FavRecipes') || []); // I want to write code that compare existedFavRecipe.Title with newTitle // if the title already exist it will give message and if not it will add the object into the local storage const NewFavRecipe = { Title : recipe.label, Image : recipe.image, Url : recipe.url, CuisineType : recipe.cuisineType, mealType : recipe.mealType, IngredientList: recipe.ingredients, Status : JSON.stringify(click) } existedFavRecipe.push(NewFavRecipe); localStorage.setItem('FavRecipes',JSON.stringify(existedFavRecipe)); } }

y setData() se activará con onClick

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías hacer algo como: const exists = existedFavRecipe.some((recipe) => recipe['Title'] == newTitle)

existedFavRecipe sobre la matriz existFavRecipe para verificar si el valor ya existe

 if(!exists) { const NewFavRecipe = { Title : recipe.label, Image : recipe.image, Url : recipe.url, CuisineType : recipe.cuisineType, mealType : recipe.mealType, IngredientList: recipe.ingredients, Status : JSON.stringify(click) } existedFavRecipe.push(NewFavRecipe); localStorage.setItem('FavRecipes',JSON.stringify(existedFavRecipe)); }
about 4 years ago · Juan Pablo Isaza Report
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!