1から10までの数字
Javascript - Node.js
for(let i = 1; i <= 10; i++){
console.log(i);
};
Python
for i in range(1, 11):
print(i)
50 ~ 100 までの数字を表示
Javascript - Node.js
let [start, end] = [50, 101];
let arry = [...new Array(end - start).keys()].map((n) =< n + start);
for(let i of arry){
console.log(i)
}
Python
for i in range(50, 101):
print(i)
配列の値を順番に取得
Javascript - Node.js
let fruits = ["apple", "orange", "banana"]
for(let i of fruits){
console.log(i)
}
Python
fruits = ["apple", "orange", "banana"]
for i in fruits:
print(i)
オブジェクトのキーと値を順番に取得
Javascript - Node.js
let fruits = {
"apple": 100,
"orange": 80,
"banana": 60
}
for(let [i, j] of Object.entries(fruits)){
console.log(i + ":" + j)
}
Python
fruits = {
"apple": 100,
"orange": 80,
"banana": 60
}
for name in fruits.keys():
price = fruits[name]
print(name + ":" + str(price))
配列の中にオブジェクトがある2次元連想配列
Javascript - Node.js
let fruits = [
{"name": "apple", "price": 100},
{"name": "orange", "price": 80},
{"name": "banana", "price": 60}
]
for(let i of fruits){
console.log(i["name"] + ":" + i["price"])
}
Python
fruits = [
{"name": "apple", "price": 100},
{"name": "orange", "price": 80},
{"name": "banana", "price": 60}
]
for i in fruits:
print(i["name"] + ":" + str(i["price"]))