我對 python 很友好,但我需要在谷歌應用程式腳本中使用相同的代碼。(代碼在正文下方)
先感謝您
我需要這樣的輸出:
plus = [[600, 'ter', 'simple'], [600, 'ter', 'simple']]
這是我的代碼:
function myFunction() {
var data =[[600, 'ter', 'simple'], [600, 'ter', 'simple'], [300, 'ter', 'medium'], [200, 'ter', 'Hard']]
var plus = []
for (let i = data[0]; i < data.leng; i )
{
if ( data[i][0] == data[0][0])
{
plus.push(data)
}
}
}
uj5u.com熱心網友回復:
這里和那里有幾個語法錯誤。在代碼中指出它們:
/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
function myFunction() {
var data = [
[600, 'ter', 'simple'],
[600, 'ter', 'simple'],
[300, 'ter', 'medium'],
[200, 'ter', 'Hard'],
];
var plus = [];
for (
let i = 0 /* intializer or counter should start with 0 not data[0] */;
i < data.length /* No property named leng data.leng */;
i
) {
if (data[i][0] == data[0][0]) {
plus.push(
data[
i
] /* push only the current element `data[i]` and not the full `data` array */
);
}
}
console.log(plus);
}
myFunction();
<!-- https://meta.stackoverflow.com/a/375985/ --> <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>
uj5u.com熱心網友回復:
使用Array.filter(),像這樣:
function filterData() {
const data = [
[600, 'ter', 'simple'],
[600, 'ter', 'simple'],
[300, 'ter', 'medium'],
[200, 'ter', 'Hard'],
];
const filterBy = { column: 0, value: data[0][0] };
return data.filter(row => row[filterBy.column] === filterBy.value);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/391789.html
標籤:javascript for循环 if 语句 谷歌应用程序脚本
