简体   繁体   English

如何从jquery数组中删除双引号

[英]How to remove double quotes from jquery array

I have a variable which contains the values like this .. 我有一个变量,其中包含这样的值..

["09:09:49", "00:14:09", "00:05:50", "02:38:02", "01:39:28"]

Now as per my need i have to formate like this .. 现在根据我的需要,我必须像这样形成..

[09:09:49, 00:14:09, 00:05:50, 02:38:02, 01:39:28]

for this i tried 为此,我试过

 callduration=[];
 callduration=["09:09:49", "00:14:09", "00:05:50", "02:38:02", "01:39:28"];
 var newstring = callduration.replace(/\"/g,'');

But it is giving error .. 但它给出了错误..

TypeError: callduration.replace is not a function
var newstr=callduration.replace(/\"/g,'');

Please help me. 请帮我。 Thanks in advance.. 提前致谢..

First off, you must note that callduration is an array. 首先,您必须注意callduration是一个数组。 Arrays do not have a replace method, hence the error. 数组没有replace方法,因此错误。

As mentioned by @Felix Kling , the quotes are just string delimiters. 正如@Felix Kling所提到的,引号只是字符串分隔符。 They are not part of the string values contained in your array of strings. 它们不是字符串数组中包含的字符串值的一部分。 For example, when accessing callduration[0] you will get a string containing the 09:09:49 sequence of characters. 例如,当访问callduration[0]您将获得一个包含09:09:49字符序列的字符串。

However, if you really need a string in the requested format, here it is: 但是,如果您确实需要所请求格式的字符串,那么它是:

var callduration = ["09:09:49", "00:14:09", "00:05:50", "02:38:02", "01:39:28"];
var newstr = '[' + callduration.join(', ') + ']';
newstr; //"[09:09:49, 00:14:09, 00:05:50, 02:38:02, 01:39:28]"

Though this probably won't be of much use unless you have some very specific use case in mind. 虽然这可能没什么用,除非你有一些非常具体的用例。

callduration is an array. callduration是一个数组。 That means it contains a sequential, ordered list of items. 这意味着它包含一个顺序的,有序的项目列表。 Those items must be something that can exisdt in javascript. 这些项目必须是javascript中可以存在的东西。 As your array exists like this: 由于您的数组存在如下:

["09:09:49", "00:14:09", "00:05:50", "02:38:02", "01:39:28"]

it is an array of strings. 它是一个字符串数组。 Each time value is represented by its own string. 每个时间值由其自己的字符串表示。 The quote marks are not actually part of the string - that' just how a string is represented when typing it. 引号实际上不是字符串的一部分 - 这就是键入字符串时的表示方式。

If you want the array to be an array of something other than strings, you would need to specify what data type you want it to be. 如果希望数组是除字符串以外的数组,则需要指定所需的数据类型。 09:09:49 as you've asked, it not a legal javascript piece of data. 09:09:49正如你所问,这不是一个合法的javascript数据。

Some choices that you could use: 您可以使用的一些选择:

  1. An array of numbers where each number represents a time value (say milliseconds since midnight). 一个数字数组,其中每个数字代表一个时间值(比如午夜以来的毫秒数)。

  2. An array of Date objects. Date对象的数组。

If you have an array of strings now and you wanted to convert it to either of the above, you would loop through your existing array, parse the string you have now into an actual numeric time and then convert that into whatever numeric or object format you want to be in the array. 如果你现在有一个字符串数组并且你想将它转换为上面的任何一个,你将遍历现有的数组,将现在的字符串解析为实际的数字时间,然后将其转换为任何数字或对象格式想要在阵列中。

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

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