I would like to get a list of key names based on a value I check.
This is what I have.
const data = {
"DE": "ARUN",
"HI": "ARUN",
"PR": "ARUN",
"TX": "ARUN",
"MA": "ARUN",
"MD": "CHARLES,BRANDON,DAVID,ARUN",
"IA": "ARUN",
"ME": "ARUN",
"ID": "ARUN",
"MI": "ARUN",
"UT": "ARUN",
"MN": "ARUN",
"MO": "ARUN",
"IL": "ARUN",
"IN": "ARUN",
"MS": "ARUN",
"MT": "ARUN",
"AK": "ARUN",
"AL": "ARUN",
"VA": "ARUN",
"AR": "ARUN",
"AS": "ARUN",
"VI": "ARUN",
"NC": "ARUN",
"ND": "ARUN",
"NE": "ARUN",
"RI": "ARUN",
"AZ": "ARUN",
"NH": "ARUN",
"NJ": "ARUN",
"VT": "ARUN",
"NM": "ARUN",
"FL": "ARUN",
"NV": "ARUN",
"WA": "ARUN",
"NY": "ARUN",
"SC": "ARUN",
"SD": "ARUN",
"WI": "ARUN",
"OH": "ARUN",
"GA": "ARUN",
"OK": "ARUN",
"CA": "ARUN",
"WV": "ARUN",
"WY": "ARUN",
"OR": "ARUN",
"KS": "ARUN",
"CM": "ARUN",
"CO": "ARUN",
"GU": "ARUN",
"KY": "ARUN",
"CT": "ARUN",
"PA": "ARUN",
"LA": "ARUN",
"TN": "ARUN",
"DC": "ARUN"
}
const name = 'BRANDON'
const newMappedData = Object.keys(data).map(key => {
return {
[key]: data[key].split(',')
}
})
const filteredData = newMappedData.filter(item => Object.values(item).includes(name))
console.log(filteredData)
If you use includes
you don't even need to split
. Also you don't need to use map
to create a new array:
const data = {
"DE": "ARUN",
"HI": "ARUN",
"PR": "ARUN",
"TX": "ARUN",
"MA": "ARUN",
"MD": "CHARLES,BRANDON,DAVID,ARUN",
"IA": "ARUN",
"ME": "ARUN",
"ID": "ARUN",
"MI": "ARUN",
"UT": "ARUN",
"MN": "ARUN",
"MO": "ARUN",
"IL": "ARUN",
"IN": "ARUN",
"MS": "ARUN",
"MT": "ARUN",
"AK": "ARUN",
"AL": "ARUN",
"VA": "ARUN",
"AR": "ARUN",
"AS": "ARUN",
"VI": "ARUN",
"NC": "ARUN",
"ND": "ARUN",
"NE": "ARUN",
"RI": "ARUN",
"AZ": "ARUN",
"NH": "ARUN",
"NJ": "ARUN",
"VT": "ARUN",
"NM": "ARUN",
"FL": "ARUN",
"NV": "ARUN",
"WA": "ARUN",
"NY": "ARUN",
"SC": "ARUN",
"SD": "ARUN",
"WI": "ARUN",
"OH": "ARUN",
"GA": "ARUN",
"OK": "ARUN",
"CA": "ARUN",
"WV": "ARUN",
"WY": "ARUN",
"OR": "ARUN",
"KS": "ARUN",
"CM": "ARUN",
"CO": "ARUN",
"GU": "ARUN",
"KY": "ARUN",
"CT": "ARUN",
"PA": "ARUN",
"LA": "ARUN",
"TN": "ARUN",
"DC": "ARUN"
}
const name = 'BRANDON'
const filteredData = Object.keys(data).filter(key => data[key].includes(name))
console.log(filteredData)
I have a requirement to display additional input tags based on user radio tag. I pasted the working code here. I wanted to display spouse first name and last name input tags. If not, will have to ...
I have a requirement to display additional input tags based on user radio tag. I pasted the working code here. I wanted to display spouse first name and last name input tags. If not, will have to ...
I would like to concat sub object array inside object in javascript. I have an object array inside an object: I would like to return the department sub array into one object array. var array = { ...
I would like to concat sub object array inside object in javascript. I have an object array inside an object: I would like to return the department sub array into one object array. var array = { ...
Probably dead simple for someone out there, but I want to build a regex that will search across this string: foo[0][2] and return foo 0 2 in the array of matches So far I have come up with is \([...
Probably dead simple for someone out there, but I want to build a regex that will search across this string: foo[0][2] and return foo 0 2 in the array of matches So far I have come up with is \([...
I am studying the use of reduce in javascript, and I am trying to restructure an Array of Objects in a generic way - need to be dynamic. flowchart - i get totaly lost I started with this through. ...
I am studying the use of reduce in javascript, and I am trying to restructure an Array of Objects in a generic way - need to be dynamic. flowchart - i get totaly lost I started with this through. ...