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

131
Views
Object is overwritten by new one in array

I know there are similar questions related to this but none of them seems to solve the issue for me.

How do prevent the push method from overwriting the existing object in the array?

Pardon the variable x by the way.

const investorValues = state.investorSelected;
    const categoryValues = state.categoryCheckbox;

    const listAsFavourite = {
        listName: "",
        listDescription: "",
        listItems: {
            categories: [],
            investors: [],
        },
        saveAsOpen: state.saveAsOpen === false ? !state.saveAsOpen : state.saveAsOpen,
        saveAsComing: state.save

> Blockquote

AsComing === false ? !state.saveAsComing : state.saveAsComing
    };

    if (investorValues !== null) {

        listAsFavourite.listItems = {
            ...listAsFavourite.listItems,
            investors: investorValues
        }
    }

    if (categoryValues !== null) {
        listAsFavourite.listItems = {
            ...listAsFavourite.listItems,
            categories: categoryValues
        }
    }

    const saveFavouriteList = () => {
        const favouriteList = []

        if (state.favouriteListName === "") {
            alert.error("List must have a title")
        } else {

            const x =  {
                ...listAsFavourite,
                listName: state.favouriteListName,
                listDescription: state.favouriteListDescription
            }
            
            favouriteList.push(x);


            localStorage.setItem("FAVOURITE_lIST", JSON.stringify(favouriteList));

            alert.success("List created");

            removeFavouriteListModal();
        }
    }
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!