gpt4 book ai didi

javascript - 如何在JS中动态获取const值

转载 作者:行者123 更新时间:2023-11-30 19:42:43 25 4
gpt4 key购买 nike

<分区>

我怎样才能像 PHP 中的 constant() 一样动态地获取常量的值?

下面,我想访问 HELL_NO,但我在变量中有 NO。为什么这会返回 undefined

const HELL_YES='warm';
const HELL_NO='cool';
var pick='NO';
console.log(window['HELL_'+pick]);

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