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

160
Views
No se puede modificar una propiedad de un objeto en una matriz después de usar el método de filtro

Tengo 2 arreglos de objetos (lo mismo): 1 (artificesToAdd[]) que puede contener 0 o más objetos y el 2nd (newFilter[]) que también puede contener de 0 a un par de objetos, basado en una búsqueda realizada por un usuario.

El objetivo es que para cada objeto contenido en la matriz artificesToAdd[], verifique si este objeto también existe en la matriz newFilter[]. Si es así, necesito actualizar la propiedad 'qtyToAdd' para indicar la cantidad que está inicialmente en mi primera matriz.

Lamentablemente me sale este error:

 'Uncaught TypeError: Cannot add property qtyToAdd, object is not extensible'

Tengo entendido que esta matriz no se puede modificar porque está en referencia, pero no estoy seguro de esto y no sé cómo resolverlo. ¿Debo crear otra matriz y empujar los elementos necesarios dentro?

El error ocurre en esta línea en particular: newFilter[artIndex].qtyToAdd = item.qty;

 const handleFilter = (event: any) => { const searchWord: string = event.target.value; const newFilter = artifices.filter((value) => { return value.codeGF.toUpperCase().includes(searchWord.toUpperCase()); }); // Now let's add ART who had a qty if (artificesToAdd.length > 0) { let artIndex: number; artificesToAdd.forEach(function (item) { artIndex = newFilter.findIndex((i) => i.id === item.id); if (artIndex === -1 || artIndex === undefined) return; console.log(newFilter[artIndex]); newFilter[artIndex].qtyToAdd = item.qty; }); } setFilteredArtifices(newFilter); };
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Esto podría ser un alcance, pero intente cambiar esto: "const newFilter =" a esto: "let newFilter="

about 4 years ago · Santiago Gelvez 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!