array.find()方法

//array.find(function(currentValue, index, arr),thisValue)  方法说明

let tempArray = [
{"key":100,"key2":"sdfsdf"},
{"key":210,"key2":"dfgdg"},
{"key":310,"key2":"sdfsdfbh"},
];
this.tempValue = 210;
let result = tempArray.find(function (item) {
return item.key == this.tempValue;
},this);
cc.log('---log--- gmk result' + jsonencode(result));

//---log--- gmk result{"key":210,"key2":"dfgdg"}
posted @ 2019-08-15 11:23  流星曳尾  阅读(3411)  评论(0编辑  收藏  举报