Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jquery中拆分字符串数组_Jquery - Fatal编程技术网

如何在jquery中拆分字符串数组

如何在jquery中拆分字符串数组,jquery,Jquery,如何在jquery中拆分字符串数组。 例如: var input='a,b,c,d,e,f,g' //i want to split in in array. //check the condition that if input of elements > 3. //then i need to remove the elements in array. then show the array like ex: output= 'a,b,c' 由于我不熟悉jQuery,请向我推荐

如何在jquery中拆分字符串数组。 例如:

var input='a,b,c,d,e,f,g'
//i want to split in in array.
//check the condition that if  input of elements > 3. 
//then i need to remove the elements in array. then show the array like ex: output= 'a,b,c' 
由于我不熟悉
jQuery
,请向我推荐一些jQuery函数来实现这一点

var output = 'a,b,c,d,e,f,g'.split(',').slice(0, 3).join();

var input='a、b、c、d、e、f、g';
var yourray=input.split(“,”);
var newArray=newArray();
如果(yourray.length>3){
对于(i=0;i<3;i++){
push(yourray[i]);
}
}

试试这把小提琴。拼接和连接


jQuery库中没有任何内容适合于此,您需要使用纯Javascript

使用将字符串拆分为数组,检查长度,如果需要获取部分数组,请使用:

var arr = input.split(',');
if (arr.length > 3) {
  arr = arr.slice(0, 3);
}
如果要将结果作为逗号分隔的字符串而不是数组,请使用:

var result = arr.join(',');
var Ainput=input.split(“,”);
var输出=输入;
如果(输入长度>3)
{
输出=”;

对于(var i=0;通过检查javascript的split方法而不是jquery开始:然后可能会发布一些代码,其中包含您一直使用的
'a、b、c、d、e、f、g'。split(',')
;请参阅也先尝试Google,不要听起来太刺耳,这确实是javascript 101。
var result = arr.join(',');
var Ainput = input.split(",");
var output = input;
if(Ainput.length > 3)
{
    output = "";
    for(var i=0;i<3;i++)
    {
        output += Ainput[i]; 
    }
}