简体   繁体   English

我如何使用变量X的值

[英]How do i use the value of variable X

docRef.update({

            sequencenumber: {
                x: false
              }

         })

In this case consider the value 在这种情况下,请考虑

x=3 X = 3

I want the field value to be 我希望字段值为

3:false 3:假

But in my database the field value is 但是在我的数据库中,字段值是

x:false X:假

In ES6 use like [variable] . 在ES6中使用[variable]

 var x=3; var a = { sequencenumber: { [x]: false } } console.log(a) 

You can use javascript's bracket notation for objects however you will have to initialise your data object sequencenumber before you can edit it. 您可以对对象使用javascript的括号表示法,但是必须先初始化数据对象的sequencenumber然后才能进行编辑。 See bellow: 见下面:

sequencenumber = {};
sequencenumber[x] = true;
docRef.update(sequencenumber);

Converting my comment to answer: 将我的评论转换为答案:

  1. use ES2015+ Computed property names : [x]:false 使用ES2015 + 计算属性名称[x]:false

  2. Use bracket notation: obj.sequencenumber[x]=false; 使用方括号表示法: obj.sequencenumber[x]=false;

 var x = 3 // ES2015+: obj = { sequencenumber: { [x]: false // } } console.log(obj) // previous versions: var obj = { sequencenumber: {} } obj.sequencenumber[x] = false; // bracket notation console.log(obj) // To read it: console.log(obj.sequencenumber[3]) // or console.log(obj.sequencenumber[x]) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 npm 脚本中使用环境变量的值? - How do I use value of env variable in npm script? 如何使用 drupal 视图字段值作为 Javascript 变量 - How do I use a drupal views field value as Javascript Variable 如何从XMLHttpRequest解析javascript中的该值并将其用作变量? - How do I parse this value in javascript from XMLHttpRequest and use it as a variable? 如何将请求变量用于字段值 - how do I use a request variable into a field value 如何使用 DOM 元素的属性值作为变量? - How do I use DOM element's attribute value as a variable? 我如何在JavaScript中使用asp.net变量值 - How do i use an asp.net variable value in javascript 如何制作始终包含变量“x”值的文本的 h1 - How do I make an h1 that always has the text of the value of the variable "x" 我如何使用 JavaScript 将输入从文本框中获取到变量然后打印变量的值? - How do i use JavaScript to take the input from a text box to a variable then print the value of a variable? 如何根据 select 标签的选定选项的值为变量分配新值,检索并使用变量的新值? - How do I assign a new value to a variable based on the value of a selected option of a select tag, retrieve and use the new value of the variable? 如何从数组中提取特定值并将这些值分配给变量以在下一个邮递员请求中使用它 - How do I extract specific value from an array and assigned those value to a variable to use it in next postman request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM