Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
Removing a specific element from an object that is located inside a parent element

I have the following object:

const jj = {
    "type": "doc",
    "content": [{
        "type": "paragraph",
        "content": [{
            "type": "text",
            "text": "HI  \n"
        }, {
            "type": "text",
            "marks": [{
                "type": "link",
                "attrs": {
                    "href": "https://infosysta-my.sharepoint.com/:x:/p/elie%5Fiskandar/EXmik99OQBBNiJua1zbbiUIBwU8QEVOzyXl3qRV3ZnhADw",
                    "__confluenceMetadata": null
                }
            }],
            "text": "Client List - MW.xlsx"
        }]
    }, {
        "type": "paragraph",
        "content": [{
            "type": "text",
            "text": "regards,"
        }]
    }],
    "version": 1
};

I need to remove the "__confluenceMetadata":null key/value so the new object will be:

const jj = {
    "type": "doc",
    "content": [{
        "type": "paragraph",
        "content": [{
            "type": "text",
            "text": "HI  \n"
        }, {
            "type": "text",
            "marks": [{
                "type": "link",
                "attrs": {
                    "href": "https://infosysta-my.sharepoint.com/:x:/p/elie%5Fiskandar/EXmik99OQBBNiJua1zbbiUIBwU8QEVOzyXl3qRV3ZnhADw"
                }
            }],
            "text": "Client List - MW.xlsx"
        }]
    }, {
        "type": "paragraph",
        "content": [{
            "type": "text",
            "text": "regards,"
        }]
    }],
    "version": 1
};

I tired to iterate through the elements using let arr = Object.entries(ADFDocJson); but I couldn't reach what I needed.

I am looking for a generic method to use as this is just an example object and there might be multiple objects in the marks array.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Presented below is one possible way to achieve the desired objective.

Code Snippet

const removeMeta = argObj => (
  Object.fromEntries(
    Object.entries(argObj)
    .map(([k, v]) => (
      k !== 'content'
      ? ([k, v])
      : ([k, (
        v.map(ob1 => (
          !('content' in ob1)
          ? ({...ob1})
          : ({...ob1,
            content: ob1.content.map(
              ob2 => (
                !('marks' in ob2)
                ? ({ ...ob2 })
                : ({ ...ob2,
                  marks: ob2.marks.map(ob3 => (
                    !('attrs' in ob3 &&
                    '__confluenceMetadata' in ob3.attrs &&
                    ob3.attrs['__confluenceMetadata'] === null
                    )
                    ? ({ ...ob3 })
                    : ({ ...ob3, 
                      attrs: Object.fromEntries(
                        Object.entries(ob3.attrs)
                        .filter(
                          (
                            [k2, v2]
                          ) => (
                            k2 !== '__confluenceMetadata'
                          )
                        )
                      )
                    })
                  ))
                })
              )
            )
          })
        ))
      )])
    ))
  )
);
const jj = {
    "type": "doc",
    "content": [{
        "type": "paragraph",
        "content": [{
            "type": "text",
            "text": "HI  \n"
        }, {
            "type": "text",
            "marks": [{
                "type": "link",
                "attrs": {
                    "href": "https://infosysta-my.sharepoint.com/:x:/p/elie%5Fiskandar/EXmik99OQBBNiJua1zbbiUIBwU8QEVOzyXl3qRV3ZnhADw",
                    "__confluenceMetadata": null
                }
            }],
            "text": "Client List - MW.xlsx"
        }]
    }, {
        "type": "paragraph",
        "content": [{
            "type": "text",
            "text": "regards,"
        }]
    }],
    "version": 1
};

console.log(removeMeta(jj));
.as-console-wrapper { max-height: 100% !important; top: 0 }

Explanation

Iterate over the various key-value pairs of the object, and then iterate over the nested 'content' arrays, identify the relevant prop and filter it out.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda