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

171
Views
Eliminar un elemento específico de un objeto que se encuentra dentro de un elemento principal

Tengo el siguiente objeto:

 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 };

Necesito eliminar "__confluenceMetadata":null para que el nuevo objeto sea:

 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 };

Me cansé de iterar a través de los elementos usando let arr = Object.entries(ADFDocJson); pero no pude alcanzar lo que necesitaba.

Estoy buscando un método genérico para usar, ya que este es solo un objeto de ejemplo y puede haber varios objetos en la matriz de marks .

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

0

A continuación se presenta una posible forma de lograr el objetivo deseado.

Fragmento de código

 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 }

Explicación

Repita los diversos pares clave-valor del objeto y, a continuación, repita las matrices de "contenido" anidadas, identifique la propiedad relevante y fíltrela.

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!