-
GCT1015
您可以为属性和数字部分采用嵌套循环,并将所有部分收集在一个数组中。let data = { Condition0: "5", Condition1: "6", LogicalOperator0: "&&", Operator0: "<", Operator1: "!=", Question0: "How do you rate our services?", Question1: "How likely are you to recommend our services to others?" }, keys = ['Question', 'Operator', 'Condition', 'LogicalOperator'], result = [], i = 0;outer: while (true) { for (const part of keys) { const key = `${part}${i}`; if (!(key in data)) break outer; result.push(data[key]); } i++;}console.log(result.join(' '));
-
当年话下
将对象分配给变量并从那里访问它:var someName = { Condition0: "5" Condition1: "6" LogicalOperator0: "&&" Operator0: "<" Operator1: "!=" Question0: "How do you rate our services?" Question1: "How likely are you to recommend our services to others?"}//Accessing the values would look like://someName.question0 + somename.operator0 + somename.condition0...如果您遍历该对象,则只能按照创建它的顺序访问它。您似乎需要以不同的顺序访问它。
-
蛊毒传说
您可以将显示属性的顺序存储到一个数组中并操作该数组const obj = { Condition0: '5', Condition1: '6', LogicalOperator0: '&&', Operator0: '<', Operator1: '!=', Question0: 'How do you rate our services?', Question1: 'How likely are you to recommend our services to others?'}const order = [ 'Question0', 'Operator0', 'Condition0', 'LogicalOperator0', 'Question1', 'Operator1', 'Condition1']const res = order.map(prop => obj[prop]).join(' ')console.log(res)