JSFiddle - React, Tailwind, and code Playground

by apasaja

JavaScript

const xyz = [
   {
     id: 394311835823360,
     typeName: "活动优惠"
   },
   {
     id: 394311838509824,
     typeName: "好友佣金"    
   },
   {
     id: 394311838509123,
     typeName: "一二三四"    
   }
]
let abc = "394311835823360,394311838509824"

let result = abc.split(",")
//console.log('data:', result)
//console.log('arr', xyz)

/* let seeResult;
let result = []
let finalResult = abc.split(",").forEach(function(entry){
	let getKeyValueById = function(array, key, id) {
		var testArray = array.slice(), test;
		while(test = testArray.pop()) {
			if (test.id == id) {
				return test[key];
			}
		}
		return;
	}

	result.push(getKeyValueById(xyz, 'typeName', entry))	
})

let end;
for(let i=0; i<result; i++) {
	if(i>1) {
		return `<div>${i}</div>`
	}
}

console.log('<<<<', result) */

/* for(let i=0; i<result.length; i++) {
	
	if(result[i] == xyz[i].id) {
		console.log('good')
	}
} */

/* for(i=0; i<xyz.length; i++) {
	data = abc.split(",")
	
	console.log(data)
} */

let list2 = abc.split(",")
console.log('aaa:', list2)

if(abc) {
	list2.forEach((data, index, arr) => {
		console.log('bbb:', data)
		let item = xyz.find(item => item.id == data);
		console.log(item)
		
		
	})

}


/* for(let key in objList) {
	let obj = {}
	
	objList[key].forEach(item => {
		console.log('abc:', item)
	})
} */

/* let data_x = abc.map(({
	typeName
}) => typeName)

console.log('>>>xxx:', data_x) */


/* let item = xyz.find(item => item.id);
console.log(item)
 */