简体   繁体   English

如何使用逗号和括号转换新字符串中的数组

[英]How to transform array in string of new string with comma and parentheses

I have a array of values that I want to transform in a new value of strings to do a query in a external service that accept the query like this:我有一个值数组,我想将其转换为新的字符串值,以便在接受如下查询的外部服务中进行查询:

/v53.0/query/?q=SELECT+Id,Name,Field FROM Table WHERE Field IN ('a0C7X0000056xmxUAA', 'a0C7X0000056x9EUAQ', 'a0C7X0000056x99UAA')

example:例子:

I have this code that transform the array:我有这个转换数组的代码:

mapIdGRD__c.map((num) => {
        return String(num);
      });

In this:在这:


[
  'a0C7X0000056xmxUAA',
  'a0C7X0000056x9EUAQ',
  'a0C7X0000056x99UAA',
  'a0C7X0000056x8YUAQ',
  'a0C7X0000056wmxUAA',
  'a0C7X0000056wmsUAA',
  'a0C7X0000056wmnUAA',
  'a0C7X0000056wmYUAQ',
  'a0C7X0000056wmTUAQ',
  'a0C7X0000056wmOUAQ'
]

And I want to transform in a new string separated with comma and parentheses like this:我想转换成一个用逗号和括号分隔的新字符串,如下所示:

(  'a0C7X0000056xmxUAA',
  'a0C7X0000056x9EUAQ',
  'a0C7X0000056x99UAA',
  'a0C7X0000056x8YUAQ',
  'a0C7X0000056wmxUAA',
  'a0C7X0000056wmsUAA',
  'a0C7X0000056wmnUAA',
  'a0C7X0000056wmYUAQ',
  'a0C7X0000056wmTUAQ',
  'a0C7X0000056wmOUAQ'
)

Is possible using some standard lib of javascript?可以使用一些标准的javascript库吗?

you can do this你可以这样做

 const array = [ 'a0C7X0000056xmxUAA', 'a0C7X0000056x9EUAQ', 'a0C7X0000056x99UAA', 'a0C7X0000056x8YUAQ', 'a0C7X0000056wmxUAA', 'a0C7X0000056wmsUAA', 'a0C7X0000056wmnUAA', 'a0C7X0000056wmYUAQ', 'a0C7X0000056wmTUAQ', 'a0C7X0000056wmOUAQ' ] const result = `(${array.map(n => `'${n}'`).join(', ')})` console.log(result)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM