gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:29:57 29 4
gpt4 key购买 nike

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

{name:"food panda", city:"selangor", phone:"0123456789"}

并使用以下代码,但它不起作用:

this.restaurant.name.toUpperCase();

我需要将 food panda 转换为 FOOD PANDA

我该怎么做?

最佳答案

toUpperCase 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

关于Javascript - 将对象的值转换为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49117117/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com