Untitled

 avatar
unknown
javascript
4 years ago
697 B
14
Indexable
const runningVehiclesJson = {
  vehicles: [{
      nearestSymbol: 1234
    },
    {
      nearestSymbol: 4321
    }
  ]
};

const otherJson = {
  symbols: [{
      symbol: 1234,
      name: "Symbol 1"
    },
    {
      symbol: 4321,
      name: "Symbol 2"
    }
  ]
};

console.log(runningVehiclesJson);
console.log(otherJson);

console.log(runningVehiclesJson.vehicles.map(vehicle => {
  return {
    ...vehicle,
    nearestSymbolName: otherJson.symbols.find(s => s.symbol === vehicle.nearestSymbol).name
  }
}));


console.log(runningVehiclesJson.vehicles.map(vehicle => {
	return {
  	...vehicle,
    nearestSymbol: otherJson.symbols.find(s => s.symbol === vehicle.nearestSymbol).name
  }
}));
Editor is loading...