Javascript-将对象的值转换为大写
我的Angular.io或IONIC中有一个对象Javascript-将对象的值转换为大写,javascript,angular,ionic-framework,Javascript,Angular,Ionic Framework,我的Angular.io或IONIC中有一个对象 {name:"food panda", city:"selangor", phone:"0123456789"} 并使用以下代码,但它不起作用: this.restaurant.name.toUpperCase(); 我需要将食品熊猫转换为食品熊猫 我该怎么做?toUpperCase()创建字符串的副本并将其更改为大写。如果要更改原始字符串,则需要重新指定该字符串: this.restaurant.name=this.restaurant.n
{name:"food panda", city:"selangor", phone:"0123456789"}
并使用以下代码,但它不起作用:
this.restaurant.name.toUpperCase();
我需要将食品熊猫
转换为食品熊猫
我该怎么做?toUpperCase()
创建字符串的副本并将其更改为大写。如果要更改原始字符串,则需要重新指定该字符串:
this.restaurant.name=this.restaurant.name.toUpperCase()
您必须保存结果值,toUpperCase()
不会修改任何内容
var d = {name:"food panda", city:"selangor", phone:"0123456789"};
var name = d.name.toUpperCase();
toUpperCase返回一个新字符串,它不会修改原始字符串
var餐厅={名称:“美食熊猫”,城市:“雪兰莪”,电话:“0123456789”};
restaurant.name.toUpperCase();
console.log(restaurant.name);//产量:食用大熊猫
var restaurantName=restaurant.name.toUpperCase();
console.log(restaurantName);//输出:FOOD PANDA
toUpperCase()
不会对原始基因进行变异。您需要将其保存回:this.restaurant.name=this.restaurant.name.toUpperCase()代码>请共享一个可能的副本,这是不确定的!您可能不想覆盖整个对象。不,可能不想,但为了向OP显示需要存储的值,它似乎已经足够了。不过你是对的,我编辑了我的答案来反映这一点。