SOURCE

{
    const list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11];
    for (let i = 0, len = list.length; i < len; i++) {
        if (list[i] === 5) {
            break;
        }
        console.log(list[i]);
    }

    for (const item of list) {
        if (item === 5) {
            break
        }
        console.log(item)
    }

    list.forEach((item, index, arr) => {
        if (item === 5) return
        console.log("index", index);
        console.log("item", item);
    })
}
{
    const list = [
        { name: "头部导航", backward: false },
        { name: "轮播", backward: true },
        { name: "页脚", backward: false }
    ];
    const someBackward = list.some(item => item.backward);
    const eveyNewest = list.every(item => !item.backward);
    console.log(someBackward);
    console.log(eveyNewest);
}
{
    const list = [
        { name: "头部导航", type: 'nav', id: 1 },
        { name: "轮播", type: 'content', id: 2 },
        { name: "页脚", type: 'nav', id: 3 },
        { name: "页脚", type: 'nav' }
    ];
    const resultList = list.filter(item => {
        console.log(item);
        return item.type === 'nav';
    });
    console.log(resultList);

    const newList = list.map(item => {
        console.log(item);
        return item.id;
    })
    console.log("newList", newList);
}
{
    const list = [
        {
            name: "头部导航", id: 1
        },
        {
            name: "轮播", id: 2
        },
        {
            name: "页脚",
            id: 3
        }
    ];
    const result = list.find(item => item.id === 3);
    console.log(result);
    result.name = '底部导航';
    console.log(list);
    const index = list.findIndex(item => item.id === 3);
    console.log(list[index].name)

}
{
    const list = [
        {
            name:"left", width:20
        },
        {
            name:"center", width:70
        },
        {
            name:"right",width:10
        }
    ];
    const total = list.reduce((currentTotal,item)=>{
        return currentTotal+ item.width;
    },0);
    console.log(total)
}
{
    const list = [
        {
            name:"left", width:20
        },
        {
            name:"right",width:10
        },
        {
            name:"center",
            width:70
        },
        {
            name:"right",
            width:10
        },
        {
            name:"left",
            width:20
        },
        {
            name:"right",
            width:10
        }
    ];
    const repeatTime = {};
    const result = list.reduce((array,item)=>{
        if(repeatTime[item.name]){
            repeatTime[item.name]++;
            return array;
        }
        repeatTime[item.name] =1;
        return [...array,item];
    },[]);
    console.log(repeatTime);
    console.log(result);
}
{
    const list = [
        {
            name:"left",width:20
        },
        {
            name:"right",width:30
        },
        {
            name:"center",width:70
        },
        {
            name:"top",width:40
        },
        {
            name:"bottom",width:20
        }
    ];
    const max = list.reduce((curItem,item)=>{
        return curItem.width >= item.width? curItem:item ;
    });
    const min = list.reduce((curItem,item)=>{
        return curItem.width <= item.width ? curItem :item;
    });
}
console 命令行工具 X clear

                    
>
console