将Javascript数组转换为分隔的String [英] Transform Javascript Array into delimited String

查看:152
本文介绍了将Javascript数组转换为分隔的String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Javascript字符串数组,其值如A12,B50,C105等,我想把它变成一个管道分隔的字符串,如下所示:A12 | B50 | C105 ...

I have a Javascript string array with values like A12, B50, C105 etc. and I want to turn it into a pipe delimited string like this: A12|B50|C105...

我怎么能这样做?我正在使用jQuery(如果它有助于某种内置函数)。

How could I do this? I'm using jQuery (in case that helps with some kind of builtin function).

推荐答案

var pipe_delimited_string = string_array.join("|");

Array.join 是Javascript中的原生数组方法它将数组转换为字符串,由指定的分隔符连接(可以是空字符串,一个字符或多个字符)。

Array.join is a native Array method in Javascript which turns an array into a string, joined by the specified separator (which could be an empty string, one character, or multiple characters).

这篇关于将Javascript数组转换为分隔的String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆