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

260
Views
JavaScript / Vue: ¿cómo puedo vaciar todo el valor de las propiedades del objeto?

Tengo este objeto:

 mappingData: { id_feed : "some data...", mapping_name: "some data...", xml_file_url: "some data...", encoding: "some data...", import_period: "some data...", token: "some data...", user_id: "some data...", projectFieldOptions: [ { some object data }, { some object dat } ], safety: { action_negative_diff: "some data...", action_positive_diff: "some data...", action_diff: "some data...", auto_update_title: "some data...", auto_update_description: "some data...", auto_update_images: "some data...", import_product_variations: "some data...", }, },

¿Cómo puedo vaciar todo el valor de las propiedades de este objeto ?

Lo que estoy intentando es

 for (const prop of Object.getOwnPropertyNames(this.mappingData)) { delete this.mappingData[prop]; }
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Para responder a esta pregunta, agregué algunos cambios a este objeto. Ya que este no es realmente un objeto javascript. Así que suponga que este es su objeto javascript,

 let mappingData = { id_feed: "some data...", mapping_name: "some data...", xml_file_url: "some data...", encoding: "some data...", import_period: "some data...", token: "some data...", user_id: "some data...", projectFieldOptions: [{ jj: "vfgfgfg" }, { kk: "vfgfgf" }], safety: { action_negative_diff: "some data...", action_positive_diff: "some data...", action_diff: "some data...", auto_update_title: "some data...", auto_update_description: "some data...", auto_update_images: "some data...", import_product_variations: "some data...", }, };

Y resultado como este,

 { "id_feed": "", "mapping_name": "", "xml_file_url": "", "encoding": "", "import_period": "", "token": "", "user_id": "", "projectFieldOptions": "", "safety": "" }

La respuesta es,

 let mappingData = { id_feed: "some data...", mapping_name: "some data...", xml_file_url: "some data...", encoding: "some data...", import_period: "some data...", token: "some data...", user_id: "some data...", projectFieldOptions: [{ jj: "vfgfgfg" }, { kk: "vfgfgf" }], safety: { action_negative_diff: "some data...", action_positive_diff: "some data...", action_diff: "some data...", auto_update_title: "some data...", auto_update_description: "some data...", auto_update_images: "some data...", import_product_variations: "some data...", }, }; for (const prop of Object.getOwnPropertyNames(mappingData)) { mappingData[prop] = ""; } console.log(mappingData);

about 4 years ago · Santiago Trujillo Report

0

Puede vaciar el objeto anidado y la matriz haciendo una función recursiva.

Aquí está el objeto de entrada:

 let mappingData = { id_feed: "some data...", mapping_name: "some data...", xml_file_url: "some data...", encoding: "some data...", import_period: "some data...", token: "some data...", user_id: "some data...", projectFieldOptions: [{jj: "vfgfgfg"}, {kk: "vfgfgf"}], safety: { action_negative_diff: "some data...", action_positive_diff: "some data...", action_diff: "some data...", auto_update_title: "some data...", auto_update_description: "some data...", auto_update_images: "some data...", import_product_variations: "some data...", }, };

Esta función te devolverá el objeto vacío.

 function emptyObjectValue(obj) { for (const prop of Object.getOwnPropertyNames(obj)) { if (obj[prop] instanceof Array) { obj[prop].forEach(o => { emptyObjectValue(o); }) } else if (obj[prop] instanceof Object) { emptyObjectValue(obj[prop]); } else { console.log(obj[prop]); obj[prop] = null //or make it empty string like ""; } } return obj; } console.log(emptyObjectValue(mappingData));

La salida será así.

 { id_feed: null, mapping_name: null, xml_file_url: null, encoding: null, import_period: null, token: null, user_id: null, projectFieldOptions: [ { jj: null }, { kk: null } ], safety: { action_negative_diff: null, action_positive_diff: null, action_diff: null, auto_update_title: null, auto_update_description: null, auto_update_images: null, import_product_variations: null } }
about 4 years ago · Santiago Trujillo 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!