I have a string value and an object obj, want to convert value to array then find it in obj by value, and get name but it return undefined, what I have missed?
let value = '3,4';
let obj = {
"DistrictData": [{
"id": 3,
"name": 'blah'
}, {
"id": 4,
"name": 'oops'
}]
}
let res = value.split(',').map((v, i) => obj.DistrictData.find(o => o.id === v))
console.log(res)
===compares both the type and the value, and you're comparing astringand anumberwhich meanso.id === vwill never betrue, try using just==.