S
S
semolex2015-05-03 09:44:04
JavaScript
semolex, 2015-05-03 09:44:04

How to merge two objects in AngularJS by name or key?

Hello!
Such is the problem:
There are two arrays of objects sent from the server.

var jobs = [{
    name: "worker",
    priority: 2,
    available: true
} ... ],
var offers = [{
     name: "worker",
     date: Date.Now()
}...]

and there are about 1000 such objects in the array. How can I combine these two objects by name ("worker" in this case, but there are many names) if the name is the same? As
var merged = 
  [{
    name: "worker",
    priority: 2,
    available: true,
    date: Date.Now()
} ... ]

In general, you need to merge two objects if they have the same name.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kano, 2015-05-03
@semolex

Here is the solution - jsbin.com/heyosokuwu/1/edit?js ,console
True, it will not work under ie8 due to the lack of some methods for working with arrays (filter and map)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question