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

199
Views
cambie el atributo json na, e antes de guardar usando javascript

este es el formato json de muestra en mi aplicación.

 my arr = [ { "id": 12, "creationTimestamp": "2021-09-15 15:01:11", "groupName": "one", "$$hashKey": "object:15" }, { "id": 13, "creationTimestamp": "2021-09-15 15:01:14", "groupName": "two", "$$hashKey": "object:16" }, { "id": 14, "creationTimestamp": "2021-09-15 15:01:19", "groupName": "three", "$$hashKey": "object:17" } ]

de acuerdo con mi requisito, necesito cambiar la identificación -> groupId. Después necesito asignarlo para la nueva matriz

 my array2 [ { "groupId": 12, "creationTimestamp": "2021-09-15 15:01:11", "groupName": "one", "$$hashKey": "object:15" }, { "groupId": 13, "creationTimestamp": "2021-09-15 15:01:14", "groupName": "two", "$$hashKey": "object:16" }, { "groupId": 14, "creationTimestamp": "2021-09-15 15:01:19", "groupName": "three", "$$hashKey": "object:17" } ]

cómo hago esta modificación usando java script

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

0

Puede lograr fácilmente el resultado usando el mapa

 const my_arr = [ { id: 12, creationTimestamp: "2021-09-15 15:01:11", groupName: "one", $$hashKey: "object:15", }, { id: 13, creationTimestamp: "2021-09-15 15:01:14", groupName: "two", $$hashKey: "object:16", }, { id: 14, creationTimestamp: "2021-09-15 15:01:19", groupName: "three", $$hashKey: "object:17", }, ]; const result = my_arr.map(({ id, ...rest }) => ({ groupId: id, ...rest })); console.log(result);
 /* This is not a part of answer. It is just to give the output fill height. So IGNORE IT */ .as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Juan Pablo Isaza Report

0

Para hacer esto, puede usar los métodos Object y Array en js. Vea a continuación

 let myArray = [ { "id": 12, "creationTimestamp": "2021-09-15 15:01:11", "groupName": "one", "$$hashKey": "object:15" }, { "id": 13, "creationTimestamp": "2021-09-15 15:01:14", "groupName": "two", "$$hashKey": "object:16" }, { "id": 14, "creationTimestamp": "2021-09-15 15:01:19", "groupName": "three", "$$hashKey": "object:17" } ] let newArray = []; myArray.forEach(obj =>{ Object.assign(obj , { groupId : obj.id} ); delete obj.id; newArray.push(obj); }); console.log(newArray);

Referencias: Object.assign y Array.push

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!