• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: JavaScript Append a new object to an array of objects

Resolved: JavaScript Append a new object to an array of objects

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Hi trying to add a new object to the list of cars for particular user, below is my array of object called inventory. Ive used a find to get the user id which return.
I want to add extra objects to the cars property i.e {model: “Porsche”,year: “2009”} to the user array when the user id = 1
Is there a cleaner way of doing this without using push


Answer:

You can use Array.prototype.map and update the item that has an id of 1.


If you want don’t want to create a new array, then you can use Array.prototype.forEach instead of map.


If you have better answer, please add a comment about this, thank you!

functional-programming javascript javascript-objects reactjs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Convert function is not working with {fn } in SQL Server

24/03/2023

Resolved: Why reference in pointer array doesn’t have data?

24/03/2023

Resolved: EntityFramework creates/runs migrations using parameterless DataContext instance

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.