【发布时间】:2021-03-18 19:14:36
【问题描述】:
在练习中,我必须创建一个名为“fullAddress”的变量,它包含给定文字对象中除第一个键之外的所有内容。
我找到了一种可行的解决方案,但我觉得有更好的方法来做到这一点。另外,我不知道如何有效地在变量中的值之间放置空间。
练习表明最终结果应如下所示:
39 Johnson Ave, 布鲁克林, NY, 11206
但我的看起来像这样:
39 Johnson AveBrooklynNY11206
练习中提供的文字对象:
const restaurant = {
name: 'Ichiran Ramen',
address: `${Math.floor(Math.random() * 100) + 1} Johnson Ave`,
city: 'Brooklyn',
state: 'NY',
zipcode: '11206',
}
我的解决方案:
let fullAddress = restaurant.address + restaurant.city + restaurant.state + restaurant.zipcode;
【问题讨论】:
-
那么问题是什么?添加一个空格,中间有一个字符串。
restaurant.address + " " + restaurant.city或使用字符串模板文字。 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript key