|
|
|
สอบถามการเขียน javascript นับจำนวนข้อมูลเเยกตามเงื่อนหน่อยครับ |
|
|
|
|
|
|
|
Code (JavaScript)
const fetchApi = async (url) => {
try {
let response = await fetch(url, {
method: 'GET',
headers: {
"Content-type": "application/json; charset=UTF-8"
}
});
let data = await response.json();
return data;
} catch (error) {
return error;
}
}
fetchApi("https://random-data-api.com/api/cannabis/random_cannabis?size=30")
.then(data => {
let result = data.reduce((previousValue, currentValue, currentIndex, array) => currentValue.type == 'hybrid' ? previousValue + 1 : previousValue, 0);
console.log(result);
}).catch(error => {
console.log(error)
});
//let arr = [5, 10, 15, 20, 25].reduce((previousValue, currentValue, currentIndex, array) => currentValue > 15 ? previousValue + 1 : previousValue, 0);
//console.log(arr);
|
|
|
|
|
Date :
2022-01-05 13:16:29 |
By :
Guest |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
ca.reduce((previousValue, currentValue, currentIndex, array) => ca.idmem == 39 ? previousValue + 1 : previousValue, 0);
|
|
|
|
|
Date :
2022-01-05 13:28:26 |
By :
Guest |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|