Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-将对象的值转换为大写_Javascript_Angular_Ionic Framework - Fatal编程技术网

Javascript-将对象的值转换为大写

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

我的Angular.io或IONIC中有一个对象

{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显示需要存储的值,它似乎已经足够了。不过你是对的,我编辑了我的答案来反映这一点。