使用来自两个不同对象的数据创建句子

时间:2018-05-30 13:28:55

标签: concat sentence

根据这些数据:

const employees = {
   employee1: {name: "Susana", age: 54}, 
   employee2: {name: "Mariano", age: 55}
}

const companies = { 
   company1: {name: "General Electric"},
   company2: {name: "Apple Computers"}
};

我需要创建一个看起来像这样的句子:

Susana works at General Electric

由于两个对象都使用值name(并且我不允许更改它们),因此我没有想法如何连接它们以创建一个连贯的句子。我该怎么办?

1 个答案:

答案 0 :(得分:0)

const createSentence = function (name, company) {

   let nombre = employees.employee1['name'];
   let compania = companies.company1['name'];

   return console.log(nombre + " works at " + compania);
}

createSentence(); // "Susana works at General Electric"