Skip to content Skip to sidebar Skip to footer

Delete Array Element From Multidimensional Infinity Array

There is a specific element I want to delete. For example, I want to delete the element with id = 76 in the array below. Also, the array can go together indefinitely. The problem h

Solution 1:

A Salamu Aleykum. Try:

const filterObject = (object, id) => {
    const newObj = [];
    object.map((element) => {
        if (parseInt(element.id) === parseInt(id)) return;

        if (element.navigation_sub_categories)
            element.navigation_sub_categories = filterObject(element.navigation_sub_categories, id);
        /* Eger `navigation_sub_categories`-den basqa keyde varsa array tipli asagidakini test ede bilersen */
        // Object.entries(element).map(
        //  ([k, v]) => typeof v === "object" && Array.isArray(v) && (element[k] = filterObject(v, id)),
        // );

        newObj.push(element);
    });
    return newObj;
};

filterObject(/* object */, idWhicYouNeedDelete)

Post a Comment for "Delete Array Element From Multidimensional Infinity Array"