简体   繁体   English

在 javascript 中获取三引号

[英]Getting Triple quotes in javascript

Android mobile app is sending the body in a API of Nodejs with the request data as Android 移动应用程序在 Nodejs 的 API 中发送正文,请求数据为

{ 
    "openingHour":['"02:00PM"','"03:00PM"']
}

and in the backend system I am unable to remove either single quote or double quote using JS only.在后端系统中,我无法仅使用 JS 删除单引号或双引号。

my requirement is我的要求是

{ 
    "openingHour":["02:00PM","03:00PM"]
}

OR 

{ 
    "openingHour":['02:00PM','03:00PM']
}

how can i achieve the above requirements.我怎样才能达到上述要求。

You can use the substring function to remove the leading and trailing quote from each entry and build a new array out of it.您可以使用 substring function 从每个条目中删除前导引号和尾随引号并从中构建一个新数组。

Using the map function you can iterate over each element in the openingHour array, applying that expression, and use the array returned from map to assign it back to the json使用 map function 您可以迭代openingHour数组中的每个元素,应用该表达式,并使用从map返回的数组将其分配回 json

 let json = { "openingHour": ['"02:00PM"', '"03:00PM"'] } console.log('before', json) let newOpeningHourArray = json.openingHour.map(time => time.substring(1, time.length - 1)) json.openingHour = newOpeningHourArray console.log('after', json)

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

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