我有一个JavaScript数组:
var j_array = new Array();
j_arry=["class:1","division:a","class:5","class:3","division:b","division:c","division:d","class:10"];
我需要找出一个类出现的次数以及其数组键,因此我使用:
found = $.inArray('class', j_array); ` But it returns `-1`;
然后我使用:
var search = 'class';
$.each([j_array], function(index, value){
$.each(value, function(key, cell){
if (search.indexOf(cell) !== -1)
console.log('found in array '+index, cell);
});
});
但这也是错误的。我该如何解决这个问题?
我想从这个数组中得到以下内容:
Class coming 4 times, at key 0, 2, 3, and 7
I want to make a separate array of class only, that is,
new_array = ["class:1", "class:2", "class:3", "class:10"];
Currently there are four classes in
j_array
. How can I get theNth class value
也就是说,1st class value ="class:1"
,2nd class value="class:5"
等等。
item.indexOf(searchTerm);
。