我有一个 mybooks 数组,我想将它按图书类别分开。
var mybooks = [
['novel','BookName1','$20.00'],
['novel','BookName2','$24.00'],
['novel','BookName3','$34.00'],
['novel','BookName4','$31.00'],
['novel','BookName4','$38.00'],
['Biograph','BookName5','$28.00'],
['Biograph','BookName6','$48.00'],
['Biograph','BookName7','$50.00']
];
我是这样弄的。
for(i=0; i<mybooks.length; i++){
if ((mybooks[i][0]) == 'novel'){
var books = mybooks[i];
console.log(books);
}
};
console.log(books) 打印
["novel", "BookName1", "$20.00"]
["novel", "BookName2", "$24.00"]
["novel", "BookName3", "$34.00"]
["novel", "BookName4", "$31.00"]
["novel", "BookName4", "$38.00"]
如何使名为“拆分”的全局变量等于books