在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 想知道這兩層循環(huán)中i,和j的變化,里外層循環(huán)是怎么走的?

想知道這兩層循環(huán)中i,和j的變化,里外層循環(huán)是怎么走的?

                 for (let i = 0; i < this.temp1.length; i++) {
                        let found = false;
                        for (let j = 0; j < combination_name_list.length; j++) {
                            if (combination_name_list[j] == this.temp1[i].name) {
                                found = true;
                            }
                    if (j == combination_name_list.length - 1 && found == false) {
                                this.combination.push({
                                    "name": this.temp1[i].name,
                                    "rows1": this.temp1[i].rows,
                                    "rows2": [],
                                    "type": this.temp1[i].type
                                });
                            }
                        }
                    }

想知道這兩層循環(huán)中i,和j的變化,里外層循環(huán)是怎么走的,以及這段代碼的意思,只能看懂一半!

回答
編輯回答
失心人

1、外層循環(huán)遍歷this.temp1這個數(shù)組

2、對于this.temp1數(shù)組的每一項都執(zhí)行一下combination_name_list數(shù)組的遍歷,查找combination_name_list數(shù)組中是否有符合條件的選項(這里是通過name字段的值來做判斷的)

3、如果找到了符合條件的選項就將found變量置為true

4、如果遍歷到combination_name_list的最后一個元素仍未找到符合條件的選項,就往this.combination這個數(shù)組中添加一個元素

2018年7月10日 02:38
編輯回答
蝶戀花

這個是取差集

var temp1 = [{name:"a"},{name:"d"},{name:"c"}];
var combination_name_list = ['a'];

//結(jié)果
var combination = [{name:"d"},{name:"c"}];

combination_name_list 中存的是 temp1name

就是拿著 temp1 中 第一項 去 combination_name_list 中找 找到了 不操作 ,沒找到 將這一項加進 新數(shù)組combination 以此類推 第二項 。。。

2017年9月3日 07:09
編輯回答
故人嘆

遍歷temp1和combination_name_list兩個數(shù)組,取combination_name_list數(shù)組最后一個元素,當且僅當它的值不等于temp1數(shù)組中name值的時候,給combination數(shù)組傳遞一組當前數(shù)據(jù)。

2017年2月14日 06:19