[英]How can I add a new row to the list when I press the button in React?
你可以試試這個我不知道它是否回答了你的問題
let arr = [], // contains the 40 entries
newArray = [];
arr.map((item) => {
if(newArray.length <= 7){
return newArray.push(item);
}
});
console.log(newArray) // array with 8 entries
並添加一個新行
const createRow = (dt, main, weather, clouds, wind) => {
return newArray.push({dt, main, weather, clouds, wind});
}
使用 args 調用 createRow
createRow("20/02/2021 18:51",{...}, "cloudy","120 knots")
你只想要數組的前八個元素?
const arraysample = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const firstEight = (array) => {
let eight = [];
arraysample.forEach((obj, i) => {
if (i < 8) {
eight.push(obj);
}
})
return eight;
};
console.log(firstEight(arraysample))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.