-1

我在下面提到了数组。这些数组值来自数据库:

如果循环找到 APP 字符串,则应将剩余字段(包括 APP 值)添加到新数组中。怎么做..帮助PLZ

var applications=new Array("App", "sub", "child", "App1", "sub1", "sub0", "child1", "App2", "sub2", "child2"); 
4

1 回答 1

2

你的意思是这样吗?

var applicationArrays = [];
for (var i = 0; i < applications.length; i++) {
    if (applications[i].search("App") != -1)
        applicationArrays[applicationArrays.length] = [applications[i]];
    else
        applicationArrays[applicationArrays.length - 1].push(applications[i]);
};  

您的数组将产生以下内容:

chrome控制台日志

于 2012-08-12T22:01:35.343 回答