Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to move object properties inside an array with map

Does anyone know how I can get a property of an object to the main array with map?

something like in the example that I put here below, in this case I want to obtain the code of the course only and change the name of the key so that instead of Code it is CourseCode

let arrayData = [
{
   Id: 1,
   Name: 'test1',
   CourseId: 23,
   Courses: {
      Id: 23,
      Code: 'MAT01',
      Name: 'Course1'
   }
},
{
   Id: 2,
   Name: 'test2',
   CourseId: 24,
   Courses: {
      Id: 24,
      Code: 'MAT02',
      Name: 'Course2'
   }
}]

RESULT:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let arrayData = [
{
   Id: 1,
   Name: 'test1',
   CourseId: 23,
   CourseCode: 'MAT01',
   Courses: {
      Id: 23,
      Code: 'MAT01',
      Name: 'Course1'
   }
},
{
   Id: 2,
   Name: 'test2',
   CourseId: 24,
   CourseCode: 'MAT02',
   Courses: {
      Id: 24,
      Code: 'MAT02',
      Name: 'Course2'
   }
}]

>Solution :

you can read this reference to solve your problem
https://www.digitalocean.com/community/tutorials/4-uses-of-javascripts-arraymap-you-should-know
thanks

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading