admin管理员组文章数量:1334948
I have an object in my Angular.io or IONIC
{name:"food panda", city:"selangor", phone:"0123456789"}
and use the following code but it's not working:
this.restaurant.name.toUpperCase();
I need to convert food panda
to FOOD PANDA
.
How can I do that?
I have an object in my Angular.io or IONIC
{name:"food panda", city:"selangor", phone:"0123456789"}
and use the following code but it's not working:
this.restaurant.name.toUpperCase();
I need to convert food panda
to FOOD PANDA
.
How can I do that?
Share Improve this question edited Mar 5, 2018 at 21:21 user9441114 asked Mar 5, 2018 at 18:26 JerryJerry 1,5831 gold badge22 silver badges43 bronze badges 3-
6
toUpperCase()
doesn't mutate the original. You need to save it back:this.restaurant.name = this.restaurant.name.toUpperCase();
– Mark Commented Mar 5, 2018 at 18:29 - Please share a Minimal, Complete, and Verifiable example – Ele Commented Mar 5, 2018 at 18:31
- Possible duplicate of Swap Case on javascript – Abhijit Kar ツ Commented Mar 5, 2018 at 18:34
3 Answers
Reset to default 6toUpperCase returns a new String, it doesn't modify the original
var restaurant = { name: "food panda", city: "selangor", phone: "0123456789" };
restaurant.name.toUpperCase();
console.log(restaurant.name); // output: food panda
var restaurantName = restaurant.name.toUpperCase();
console.log(restaurantName); // output: FOOD PANDA
toUpperCase()
creates a copy of the string and changes that one to uppercase. If you want the original string to be changed, you will need to reassign the string:
this.restaurant.name = this.restaurant.name.toUpperCase();
You have to save the resulting value, toUpperCase()
does not modify anything.
var d = {name:"food panda", city:"selangor", phone:"0123456789"};
var name = d.name.toUpperCase();
Working JSFiddle
本文标签: angularJavascriptconvert value of object to uppercaseStack Overflow
版权声明:本文标题:angular - Javascript - convert value of object to uppercase - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742309450a2450571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论