// this is the input. need to iterate the tech based name from object
let obj=[
{
name:"Nithesh",
tech:["HTML","CSS","JAVA","JS"],
},
{
name:"hari",
tech:["NodeJS","CSS","React","JS"],
},
{
name:"sathish",
tech:["Angular","CSS","React","HTML"],
}
]
//and output like this. but I tried all ways but code is not working
o/p={
"HTML":["Nithesh","sathish"],
"CSS":["Nithesh","hari", "sathish"],
"JS":["Nithesh","hari"],
"React":["hari", "sathish"],
"NodeJs":["hari"],
"Angular":["sathish"],
"JAVA":["Nithesh"],
}
3
Answers
Iterate over the outer and inner arrays to find the pairs you need, and then create a new property in the result object in case you find a new language (in
tech
), and always append the currentname
to the array you have for that property:You can try this.
I would do it with Set, flat, reduce, filter, map and includes