-
三国纷争
var arr = ['管理员','用户'];var arr1 = [];var originalData = [ { name:'管理员', code:'admin' }, { name:'用户', code:'user' }, { name:'超管', code:'super' }];for(var i = 0, len = originalData.length; i < len; i++){ for(var j = 0, len1 = arr.length; j < len1; j++){ if(arr[j] == originalData[i].name){ arr1.push(originalData[i].code); } } }你说的是这个意思吗
-
慕莱坞森
const data = [ { name: '管理员', code: 'admin' }, { name: '用户', code: 'user' }, { name: '超管', code: 'super' }]const names = ['管理员', '用户']let codes = []data.forEach(dataItem => { const { name, code } = dataItem if (names.indexOf(name) !== -1) { codes.push(code) }})console.log(codes)
-
翻过高山走不出你
const data = [ { name: '管理员', code: 'admin' }, { name: '用户', code: 'user' }, { name: '超管', code: 'super' }]const names = ['管理员', '用户']let codes = data.filter(({name})=>names.indexOf(name)!==-1).map(person=>person.code)